diff --git a/ext/standard/string.c b/ext/standard/string.c index 851775503eb..3addfbd19d0 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -5276,10 +5276,10 @@ PHP_FUNCTION(substr_count) if (ac == 4) { - if (length <= 0) { + if (length < 0) { length += (haystack_len - offset); } - if ((length <= 0) || ((size_t)length > (haystack_len - offset))) { + if (length < 0 || ((size_t)length > (haystack_len - offset))) { php_error_docref(NULL, E_WARNING, "Invalid length value"); RETURN_FALSE; } diff --git a/ext/standard/tests/strings/bug74041.phpt b/ext/standard/tests/strings/bug74041.phpt new file mode 100644 index 00000000000..598e46d8807 --- /dev/null +++ b/ext/standard/tests/strings/bug74041.phpt @@ -0,0 +1,12 @@ +--TEST-- +Bug #74041: substr_count with length=0 broken +--FILE-- + +--EXPECT-- +int(0) +int(0)