diff --git a/ext/standard/string.c b/ext/standard/string.c index 4f255d4d8e9..09d68c11237 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -5770,6 +5770,10 @@ PHP_FUNCTION(substr_compare) RETURN_FALSE; } + if (offset < 0) { /* negative offset, start comparison at the end of string */ + offset = s1_len + offset; + } + if (len && offset >= s1_len) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "The start position cannot exceed initial string length."); RETURN_FALSE;