Bug #67043 [NEW]: substr_compare falsely reports equality on negative offset
| From: | php at kirk dot at | Date: | Tue, 08 Apr 2014 09:40:19 +0000 |
| Subject: | Bug #67043 [NEW]: substr_compare falsely reports equality on negative offset | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-185137@lists.php.net to get a copy of this message | ||
From: php at kirk dot at
Operating system: OS X
PHP version: 5.5.11
Package: Strings related
Bug Type: Bug
Bug description:substr_compare falsely reports equality on negative offset
Description:
------------
Since version 5.5.11 a substr_compare with a negative 3rd parameter
(=offset, thus it should start counting from the end of the string)
incorrectly reports equality.
See http://3v4l.org/8co5P
I believe the bug could have been introduced in this commit:
https://github.com/datibbaw/php-src/commit/e292391b3899ed2d80a8f44dc94074d68328c6ea
What caught my eye is the introduced cast to an unsigned integer but I
don't know if this really is the source of the bug.
Workaround: specify a length (absolute value of the negative offset)
Test script:
---------------
var_dump(substr_compare("template", "_emplate", -8));
var_dump(substr_compare("template", "_emplate", -8, 8));
Expected result:
----------------
int(21)
int(21)
Actual result:
--------------
int(0)
int(21)
--
Edit bug report at https://bugs.php.net/bug.php?id=67043&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=67043&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=67043&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=67043&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=67043&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=67043&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=67043&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=67043&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=67043&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=67043&r=support
Expected behavior: https://bugs.php.net/fix.php?id=67043&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=67043&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=67043&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=67043&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=67043&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=67043&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=67043&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=67043&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=67043&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=67043&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=67043&r=mysqlcfg