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_strpos bounds check is byte count rather than a character
count
Description:
------------
The bounds check for the offest argument in mb_strpos appears to be a byte
count rather than a character count.
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.
With the multibyte string example, when the offset is past the character
count of the string it would be expected to return a warning but instead a
warning is returned when offest is past the byte count.
Reproduce code:
---------------
<?php
$offsets = array(20, 21, 22, 53, 54);
$string_mb =
base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
$needle = base64_decode('44CC');
foreach($offsets as $i) {
echo "\n-- Offset is $i --\n";
echo "--Multibyte String:--\n";
var_dump( mb_strpos($string_mb, $needle, $i, 'UTF-8') );
echo"--ASCII String:--\n";
var_dump(mb_strpos('This is na English ta', 'a', $i));
}
?>
Expected result:
----------------
-- Offset is 20 --
--Multibyte String:--
int(20)
--ASCII String:--
int(20)
-- Offset is 21 --
--Multibyte String:--
bool(false)
--ASCII String:--
bool(false)
-- Offset is 22 --
--Multibyte String:--
Warning: mb_strpos(): Offset not contained in string. in ...\mb_strpos.php
on line 9
bool(false)
--ASCII String:--
Warning: mb_strpos(): Offset not contained in string. in ...\mb_strpos.php
on line 11
bool(false)
-- Offset is 53 --
--Multibyte String:--
Warning: mb_strpos(): Offset not contained in string. in ...\mb_strpos.php
on line 9
bool(false)
--ASCII String:--
Warning: mb_strpos(): Offset not contained in string. in ...\mb_strpos.php
on line 11
bool(false)
-- Offset is 54 --
--Multibyte String:--
Warning: mb_strpos(): Offset not contained in string. in ...\mb_strpos.php
on line 9
bool(false)
--ASCII String:--
Warning: mb_strpos(): Offset not contained in string. in ...\mb_strpos.php
on line 11
bool(false)
Actual result:
--------------
-- Offset is 20 --
--Multibyte String:--
int(20)
--ASCII String:--
int(20)
-- Offset is 21 --
--Multibyte String:--
bool(false)
--ASCII String:--
bool(false)
-- Offset is 22 --
--Multibyte String:--
bool(false)
--ASCII String:--
Warning: mb_strpos(): Offset not contained in string. in ...\mb_strpos.php
on line 11
bool(false)
-- Offset is 53 --
--Multibyte String:--
bool(false)
--ASCII String:--
Warning: mb_strpos(): Offset not contained in string. in ...\mb_strpos.php
on line 11
bool(false)
-- Offset is 54 --
--Multibyte String:--
Warning: mb_strpos(): Offset not contained in string. in ...\mb_strpos.php
on line 9
bool(false)
--ASCII String:--
Warning: mb_strpos(): Offset not contained in string. in ...\mb_strpos.php
on line 11
bool(false)
--
Edit bug report at http://bugs.php.net/?id=43840&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=43840&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=43840&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=43840&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=43840&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=43840&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=43840&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=43840&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=43840&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=43840&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=43840&r=support
Expected behavior: http://bugs.php.net/fix.php?id=43840&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=43840&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=43840&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=43840&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=43840&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=43840&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=43840&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=43840&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=43840&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=43840&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=43840&r=mysqlcfg