Mantis - Quercus
Viewing Issue Advanced Details
4568 major always 05-20-11 10:56 12-30-12 00:17
thr  
domdorn  
normal  
closed 4.0.14  
fixed  
none    
none  
0004568: str_split fails with byte string
The application is reading a byte array from disc and trying to spilt it into an array of 8 bytes to unpack it later into int values.

split_str returns correct sized array but does not set values after first array.

This works in 'native' php

(This technique is used in Wordpress 3 to read .mo translation files into memory).

<?php
        $packed = pack("c*", 10,10,10,10,-64,8,1,10,77,2,0,0,63,8,1,0,1,2,3,4,5,6,7,8);
        print 'md5='.md5($packed).'
';
        $octets = str_split($packed, 8);
        for($o = 0; $o < count($octets); $o++) {
            print '
o='.$o.' ';
            
            $unpacked=unpack("c1n1/c1n2/c1n3/c1n4/c1n5/c1n6/c1n7/c1n8", $octets[$o]);
            var_dump($unpacked);
        }
?>
In Quercus output is:

md5=f13234affbcb2464158d99a131d1b001

o=0 array(8) { ["n1"]=> int(10) ["n2"]=> int(10) ["n3"]=> int(10) ["n4"]=> int(10) ["n5"]=> int(-64) ["n6"]=> int(8) ["n7"]=> int(1) ["n8"]=> int(10) }
o=1 array(0) { }
o=2 array(0) { }

Native PHP output is:

o=0 array(8) { ["n1"]=> int(10) ["n2"]=> int(10) ["n3"]=> int(10) ["n4"]=> int(10) ["n5"]=> int(-64) ["n6"]=> int(8) ["n7"]=> int(1) ["n8"]=> int(10) }
o=1 array(8) { ["n1"]=> int(77) ["n2"]=> int(2) ["n3"]=> int(0) ["n4"]=> int(0) ["n5"]=> int(63) ["n6"]=> int(8) ["n7"]=> int(1) ["n8"]=> int(0) }
o=2 array(8) { ["n1"]=> int(1) ["n2"]=> int(2) ["n3"]=> int(3) ["n4"]=> int(4) ["n5"]=> int(5) ["n6"]=> int(6) ["n7"]=> int(7) ["n8"]=> int(8) }
 unpack_test.php [^] (435 bytes) 05-20-11 10:56

Notes
(0005307)
domdorn   
06-09-11 12:54   
fixed in current trunk, will be in 4.0.19

Thanks for reporting this bug!

php/118e
(0006131)
nam   
12-30-12 00:17   
Closing old resolved bugs.