From: Operating system: PHP version: 5.3SVN-2010-08-29 (snap) Package: mbstring related Bug Type: Bug Bug description:mb_strpos reports needle position incorrectly
Description: ------------ If code sets incorrect character set (utf-8 instead of big5 in test case), mb_strpos() can incorrectly report needle position in some cases. It looks like $offset is calculated one way and results are calculated in some other way. See test code. mb_substr($str,$pos1,1,'utf-8') can be used to see character that is in reported needle position. I understand that $str is not in UTF-8 charset, but position reported by mb_strpos() violates very basic strpos function behavior. Search is started after $offset position and result position is counted from string start. Result should not be lower than $offset or it should be boolean false. php5.3-201008291230 compiled with /configure --prefix=/somepath --enable-cli --disable-all --enable-mbstring Also tested PHP 5.2.0 (debian etch), 5.3.2-2 (debian squeeze) and 5.2.13 (standard PHP package). 5.2.13 and 5.3.2 results are the same. 5.2.0 results are a little bit different, but I was able to reproduce position calculation problem with more complex code. Test script: --------------- $str = "\xb7\x51 &\xb4\xa6\xb6\x7d"; $pos1 = mb_strpos($str,'&',0,'utf-8'); var_dump($pos1); $pos2 = mb_strpos($str,'&',$pos1 + 1,'utf-8'); var_dump($pos2); Expected result: ---------------- second var_dump() result should be higher than first one or should be boolean false. result should not be lower than offset. Actual result: -------------- int(2) int(2) -- Edit bug report at http://bugs.php.net/bug.php?id=52731&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=52731&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=52731&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=52731&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=52731&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=52731&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=52731&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=52731&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=52731&r=needscript Try newer version: http://bugs.php.net/fix.php?id=52731&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=52731&r=support Expected behavior: http://bugs.php.net/fix.php?id=52731&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=52731&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=52731&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=52731&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=52731&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=52731&r=dst IIS Stability: http://bugs.php.net/fix.php?id=52731&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=52731&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=52731&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=52731&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=52731&r=mysqlcfg