From: yar_helg at mail dot ru Operating system: PHP version: 5.2.6 PHP Bug Type: Strings related Bug description: substr works incorrect with binary data
Description: ------------ When trying to operate with binary data using substr and mb_internal_encoding is set to UTF-8 (but no function overloading is set) substr works wrong - wrong number of bytes is returned after function call P.S. emptyfile.xls used in example is an empty MS Excel 2003 file. It can be downloaded at http://an-best.ru/empty_file.xls (13/5 Kbytes) P.P.S. IDENTIFIER_OLE constant is taken from Spreadsheet_excel_reader class. Reproduce code: --------------- <?php echo "function overload = ".ini_get('mbstring.func_overload')."<br />\n"; // Uncomment this for demonstration of wrong behaviour //mb_internal_encoding('UTF-8'); echo "MB_INTERNAL_ENCODING =".mb_internal_encoding()."<br />\n"; define('IDENTIFIER_OLE', pack("CCCCCCCC",0xd0,0xcf,0x11,0xe0,0xa1,0xb1,0x1a,0xe1)); $data = file_get_contents($_SERVER['DOCUMENT_ROOT'].'/substr_bug/emptyfile.xls'); echo "Data length = ".strlen($data)."<br />\n"; echo "First 8 symbols ==>".var_export(substr($data,0,8),1)."<== <br />\n"; echo "Compare result (substr(\$data,0,8)==IDENTIFIER_OLE) - ".var_export(substr($data,0,8)==IDENTIFIER_OLE,1)."<br />\n"; echo "Substring length (substr(\$data,0,8)) - ".strlen(substr($data,0,8))."<br />\n"; ?> Expected result: ---------------- function overload = 0 MB_INTERNAL_ENCODING =ISO-8859-1 Data length = 13824 First 8 symbols ==>'поЮ║╠А'<== Compare result (substr($data,0,8)==IDENTIFIER_OLE) - true Substring length (substr($data,0,8)) - 8 Actual result: -------------- // This result can be seen if mb_internal_encoding is set to UTF-8 function overload = 0 MB_INTERNAL_ENCODING =UTF-8 Data length = 13824 First 8 symbols ==>'поЮ║╠А' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . ''<== Compare result (substr($data,0,8)==IDENTIFIER_OLE) - false Substring length (substr($data,0,8)) - 13 -- Edit bug report at http://bugs.php.net/?id=45311&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=45311&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=45311&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=45311&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=45311&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=45311&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=45311&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=45311&r=needscript Try newer version: http://bugs.php.net/fix.php?id=45311&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=45311&r=support Expected behavior: http://bugs.php.net/fix.php?id=45311&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=45311&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=45311&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=45311&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=45311&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=45311&r=dst IIS Stability: http://bugs.php.net/fix.php?id=45311&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=45311&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=45311&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=45311&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=45311&r=mysqlcfg
