Avoid passing invalid offset to mb_strpos

Bug: T285978
Change-Id: I3d100fd05f34fe3b01ecbbce5361badc613f9406
This commit is contained in:
Daimona Eaytoy 2021-07-02 13:11:38 +02:00
parent 6dc2c068b5
commit 069fa064f5
2 changed files with 8 additions and 2 deletions

View file

@ -1268,7 +1268,11 @@ class AbuseFilterCachingParser extends AFPTransitionBase {
if ( $needle === '' ) {
return new AFPData( AFPData::DINT, -1 );
}
// Special handling for when the offset is not contained in $haystack. PHP can emit a warning
// or throw an error depending on the version (T285978). TODO Should we also throw?
if ( $offset > mb_strlen( $haystack ) ) {
return new AFPData( AFPData::DINT, -1 );
}
$result = mb_strpos( $haystack, $needle, $offset );
if ( $result === false ) {

View file

@ -1,4 +1,6 @@
strpos( "foobarfoo", "foo" ) === 0 &
strpos( "foobarfoo", "" ) === -1 &
strpos( "foobarfoo", "foo", 1 ) === 6 &
strpos( "foobarfoo", "lol" ) === -1
strpos( "foobarfoo", "lol" ) === -1 &
/* Offset not contained in the haystack */
strpos( "foo", "o", 123456 ) === -1