Mantis - Quercus
Viewing Issue Advanced Details
3367 minor always 03-03-09 22:57 03-04-09 16:52
koreth  
nam  
normal  
closed 4.0.0  
fixed  
none    
none 4.0.0  
0003367: String indexing fails with binary data
<?php
$x = "\x90";
print $x[0];

Throws an exception:

[22:55:30.410] {http--8080-10} java.lang.ArrayIndexOutOfBoundsException: -112
[22:55:30.410] {http--8080-10} at com.caucho.quercus.env.StringBuilderValue.charValueAt(StringBuilderValue.java:733)

The following patch fixes it.

--- a/modules/quercus/src/com/caucho/quercus/env/StringBuilderValue.java
+++ b/modules/quercus/src/com/caucho/quercus/env/StringBuilderValue.java
@@ -728,7 +728,7 @@ public class StringBuilderValue
     if (index < 0 || len <= index)
       return UnsetStringValue.UNSET;
     else {
- byte ch = _buffer[(int) index];
+ int ch = _buffer[(int) index] & 0xff;
 
       return CHAR_STRINGS[ch];
     }

Notes
(0003861)
nam   
03-04-09 16:52   
php/04a1