Bug #80285 [NEW]: strspn $length argument may no longer exceed the string bounds
| From: | paul dot crovella at gmail dot com | Date: | Mon, 26 Oct 2020 16:11:15 +0000 |
| Subject: | Bug #80285 [NEW]: strspn $length argument may no longer exceed the string bounds | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-229928@lists.php.net to get a copy of this message | ||
From: paul dot crovella at gmail dot com
Operating system:
PHP version: 8.0.0RC2
Package: Unknown/Other Function
Bug Type: Bug
Bug description:strspn $length argument may no longer exceed the string bounds
Description:
------------
This commit[1] changed not just out-of-bounds offsets of strspn to throw
ValueError, but lengths that exceed the string bounds as well.
Given that a positive $length argument functions as a max-length for the
match attempt, the prior behavior of accepting a length beyond the
string bounds makes sense and reverting to it would realign with substr
whose length parameter serves a similar purpose.
Is something gained by breaking existing code and requiring:
strspn($subject, $mask, $start, min($length, strlen($subject) -
$start))
where:
strspn($subject, $mask, $start, $length)
seemed to work fine as intended prior?
[1]
https://github.com/php/php-src/commit/5d9ab53a5d53f11a18ae11ed31b17ff87c8d52a7
Test script:
---------------
<?php
var_dump(
strspn("foo", "asdf", 0, 4),
strspn("fffff", "asdf", 0, 4)
);
Expected result:
----------------
int(1)
int(4)
Actual result:
--------------
Fatal error: Uncaught ValueError: strspn(): Argument #4 ($length) must
be contained in argument #1 ($str) in /in/J05AD:4
--
Edit bug report at https://bugs.php.net/bug.php?id=80285&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80285&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80285&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80285&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80285&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80285&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80285&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80285&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80285&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80285&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80285&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80285&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80285&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80285&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80285&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80285&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80285&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80285&r=mysqlcfg