Bug #73913 [NEW]: broken strrpos with negative offset

From: Date: Wed, 11 Jan 2017 17:16:38 +0000
Subject: Bug #73913 [NEW]: broken strrpos with negative offset
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-206529@lists.php.net to get a copy of this message
From:             proartex at mail dot ru
Operating system: macOS Sierra 10.12.1
PHP version:      5.6.29
Package:          Strings related
Bug Type:         Bug
Bug description:broken strrpos with negative offset

Description:
------------
It is seems broken at least in the following cases:
 - if negative offset equals to haystack length;
 - if negative offset less than needle length;
 - if needle length equals to (haystack length + negative offset)

Negative offset should not move pointer but reduce search scope on the
value of offset. In that case character placed at 0 position must not be
found if search scope is reduced to empty string. Same should be applied
in boundary cases: character placed next to reduced search scope must
not be found (last case).

Test script:
---------------
<?php

var_dump(strrpos("aaaa", 'aa', -2)); //ER: 0, AR: 2
var_dump(strrpos("aaaa", 'a', -1)); //ER: 2, AR: 3
var_dump(strrpos("/documents/show/5474", '/', -20)); //ER: false, AR: 0
var_dump(strrpos("works_like_a_charm", 'charm', -3)); //ER: false, AR:
13
var_dump(strrpos("works_like_a_charm", 'charm', -4)); //ER: false, AR:
13

Expected result:
----------------
0
2
false
false
false

Actual result:
--------------
2
3
0
13
13

-- 
Edit bug report at https://bugs.php.net/bug.php?id=73913&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=73913&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=73913&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=73913&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=73913&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=73913&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=73913&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=73913&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=73913&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=73913&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=73913&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=73913&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=73913&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=73913&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73913&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=73913&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=73913&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=73913&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=73913&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=73913&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=73913&r=mysqlcfg



Thread (7 messages)

« previous php.bugs (#206529) next »