From: josmessa at uk dot ibm dot com Operating system: Windows XP PHP version: 5.2CVS-2008-01-14 (snap) PHP Bug Type: mbstring related Bug description: mb_strrpos offset is byte count for negative values
Description: ------------ The offset argument appears to do a byte count for negative values of offset. In the example below, $string_ascii is 21 characters long and $string_mb is 21 characters (53 bytes) long. In both cases the needle appears twice, first at position 9 and secondly at position 20. When the offset is -24, beyond the character length of the string, it finds $needle at position 9, when $needle would be expected to be found when offest is -12 (i.e. behave the same as the ASCII example). It's also worth noting that strrpos returns a notice when the offset is outside the boundary of the string whereas mb_strrpos does not. This may be linked to this bug: http://bugs.php.net/43840. Reproduce code: --------------- <?php $offsets = array(-25, -24, -13, -12); $string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); $needle = base64_decode('44CC'); foreach ($offsets as $i) { echo "\n-- Offset is $i --\n"; echo "Multibyte String:\t"; var_dump( mb_strrpos($string_mb, $needle, $i, 'UTF-8') ); echo "ASCII String:\n"; echo "mb_strrpos:\t\t"; var_dump(mb_strrpos('This is na English ta', 'a', $i)); echo "strrpos:\t\t"; var_dump(strrpos('This is na English ta', 'a', $i)); } ?> Expected result: ---------------- -- Offset is -25 -- Multibyte String: Notice: mb_strrpos(): Offset is greater than the length of haystack string in ...\mb_strrpos.php on line 9 bool(false) ASCII String: mb_strrpos: Notice: mb_strrpos(): Offset is greater than the length of haystack string in ...\mb_strrpos.php on line 14 bool(false) strrpos: Notice: strrpos(): Offset is greater than the length of haystack string in ...\mb_strrpos.php on line 14 bool(false) -- Offset is -24 -- Multibyte String: Notice: mb_strrpos(): Offset is greater than the length of haystack string in ...\mb_strrpos.php on line 9 bool(false) ASCII String: mb_strrpos: Notice: mb_strrpos(): Offset is greater than the length of haystack string in ...\mb_strrpos.php on line 14 bool(false) strrpos: Notice: strrpos(): Offset is greater than the length of haystack string in ...\mb_strrpos.php on line 14 bool(false) -- Offset is -13 -- Multibyte String: bool(false) ASCII String: mb_strrpos: bool(false) strrpos: bool(false) -- Offset is -12 -- Multibyte String: int(9) ASCII String: mb_strrpos: int(9) strrpos: int(9) Actual result: -------------- -- Offset is -25 -- Multibyte String: bool(false) ASCII String: mb_strrpos: bool(false) strrpos: Notice: strrpos(): Offset is greater than the length of haystack string in ...\mb_strrpos.php on line 14 bool(false) -- Offset is -24 -- Multibyte String: int(9) ASCII String: mb_strrpos: bool(false) strrpos: Notice: strrpos(): Offset is greater than the length of haystack string in ...\mb_strrpos.php on line 14 bool(false) -- Offset is -13 -- Multibyte String: int(9) ASCII String: mb_strrpos: bool(false) strrpos: bool(false) -- Offset is -12 -- Multibyte String: int(9) ASCII String: mb_strrpos: int(9) strrpos: int(9) -- Edit bug report at http://bugs.php.net/?id=43841&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=43841&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=43841&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=43841&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=43841&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=43841&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=43841&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=43841&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=43841&r=needscript Try newer version: http://bugs.php.net/fix.php?id=43841&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=43841&r=support Expected behavior: http://bugs.php.net/fix.php?id=43841&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=43841&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=43841&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=43841&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=43841&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=43841&r=dst IIS Stability: http://bugs.php.net/fix.php?id=43841&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=43841&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=43841&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=43841&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=43841&r=mysqlcfg