Skip to content

Commit 7ccecfe

Browse files
committed
Revert "Move out of bound offset into the switch error code handler"
This reverts commit 3adc3e2423794c0cc75286766481f05710858cd0.
1 parent 00c0bb7 commit 7ccecfe

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

ext/mbstring/mbstring.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2100,6 +2100,17 @@ PHP_FUNCTION(mb_strpos)
21002100
RETURN_FALSE;
21012101
}
21022102

2103+
if (offset != 0) {
2104+
size_t slen = mbfl_strlen(&haystack);
2105+
if (offset < 0) {
2106+
offset += slen;
2107+
}
2108+
if (offset < 0 || offset > slen) {
2109+
zend_value_error("Offset not contained in string");
2110+
RETURN_THROWS();
2111+
}
2112+
}
2113+
21032114
n = mbfl_strpos(&haystack, &needle, offset, reverse);
21042115
if (!mbfl_is_error(n)) {
21052116
RETVAL_LONG(n);
@@ -2116,9 +2127,6 @@ PHP_FUNCTION(mb_strpos)
21162127
case 8:
21172128
zend_value_error("Argument is empty");
21182129
RETURN_THROWS();
2119-
case 16:
2120-
zend_value_error("Offset not contained in string");
2121-
RETURN_THROWS();
21222130
default:
21232131
zend_value_error("Unknown error in mb_strpos");
21242132
RETURN_THROWS();

0 commit comments

Comments
 (0)