#45923 [NEW]: mb_stripos & mb_strripos offset not handled correctly

[email protected] ("d_kelsey at uk dot ibm dot com")
Newsgroups php.bugs
Message-ID <[email protected]>
From:             d_kelsey at uk dot ibm dot com
Operating system: Windows XP
PHP version:      5.2.6
PHP Bug Type:     mbstring related
Bug description:  mb_stripos & mb_strripos offset not handled correctly

Description:
------------
The offset checking in mb_stripos and mb_strripos doesn't match the case
sensitive equivalents with regard to character counts rather than byte
counts. More importantly entering a negative offset in mb_strripos results
in a "Offset not contained in string." message which was not expected.

Suggested code changes.

mb_stripos function add the check:
	if (offset < 0 || (unsigned long)offset > (unsigned
long)mbfl_strlen(&old_haystack)) {
		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset not contained in
string.");
		RETURN_FALSE;
	}

mb_strripos function add the check: 
	if ((offset > 0 && offset > mbfl_strlen(&old_haystack)) ||
		(offset < 0 && -offset > mbfl_strlen(&old_haystack))) {
		php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Offset is greater than the
length of haystack string");
		RETURN_FALSE;
	}


php_mb_stripos function remove the check:
		if (offset < 0 || (unsigned long)offset > haystack.len) {
			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset not contained in
string.");
			break;
		}



Reproduce code:
---------------
<?php
var_dump(mb_strripos("abc abc abc", "b", -3));
?>

Expected result:
----------------
int(5)

Actual result:
--------------
Warning: mb_strripos(): Offset not contained in string. in
C:\udata-eclipse\p8\a.phpcode\testmb.php on line 2
bool(false)

-- 
Edit bug report at http://bugs.php.net/?id=45923&edit=1
-- 
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=45923&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=45923&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=45923&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=45923&r=fixedcvs
Fixed in release:             http://bugs.php.net/fix.php?id=45923&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=45923&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=45923&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=45923&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=45923&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=45923&r=notwrong
Not enough info:              http://bugs.php.net/fix.php?id=45923&r=notenoughinfo
Submitted twice:              http://bugs.php.net/fix.php?id=45923&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=45923&r=globals
PHP 4 support discontinued:   http://bugs.php.net/fix.php?id=45923&r=php4
Daylight Savings:             http://bugs.php.net/fix.php?id=45923&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=45923&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=45923&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=45923&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=45923&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=45923&r=mysqlcfg
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.