php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47102 strripos issues unexpected warning with UNICODE haystack
Submitted: 2009-01-14 16:06 UTC Modified: 2009-01-17 20:43 UTC
From: wharmby at uk dot ibm dot com Assigned:
Status: Closed Package: Strings related
PHP Version: 6CVS-2009-01-14 (snap) OS: Windows XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: wharmby at uk dot ibm dot com
New email:
PHP Version: OS:

 

 [2009-01-14 16:06 UTC] wharmby at uk dot ibm dot com
Description:
------------
I get an unexpected warning msg when I specify an haystack with a non-zero offset. 


I think the problem lies in the following code in ext/standard/string.c  

2913  if (haystack_type == IS_UNICODE) {
2914   	if (offset >= 0) {
2915 	   U16_FWD_N(haystack.u, cu_offset, haystack_len, offset);
2916 	   if (cu_offset > haystack_len - needle_len) {
2917 	   php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Offset is greater than the length of haystack string");
2918  	   RETURN_FALSE;
2919 	}
2920 	u_p = haystack.u + cu_offset;
2921 	u_e = haystack.u + haystack_len - needle_len;
2922  } else { 

If (cu_offset > haystack_len - needle_len) then FALSE should be returned but the warning is bogus; that should only be output if cu_offset > haystack_len.

Reproduce code:
---------------
<?php

$haystack = "abcdefg";
$needle = "abcdefg";
var_dump( strripos($haystack, $needle, 0) );
var_dump( strripos($haystack, $needle, 1) );

?>

Expected result:
----------------
int(0)
bool(false)

Actual result:
--------------
int(0)
bool(false)
PHP Notice:  strripos(): Offset is greater than the length of haystack string in .... etc 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-01-15 13:43 UTC] wharmby at uk dot ibm dot com
8 new tests for strripos() just checked into CVS. 3 fail on PHP6 because of this bug and have XFAIL sections which need removing once this bug is fixed. They are:

ext/standard/tests/strings/strripos_basic2
ext/standard/tests/strings/strripos_variation1	
ext/standard/tests/strings/strripos_variation2
 [2009-01-17 20:43 UTC] felipe@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Thanks Andy.

Fixed and removed the XFAIL sections.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Jan 17 21:01:24 2020 UTC