diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c index 2ee6306bfb42..f240b86b4788 100644 --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@ -1910,6 +1910,9 @@ static unsigned char* offset_to_pointer_utf8(unsigned char *str, unsigned char * } pos += u8_tbl[*pos]; } + if (pos > end) { + pos = end; + } return pos; } } diff --git a/ext/mbstring/tests/gh23106.phpt b/ext/mbstring/tests/gh23106.phpt new file mode 100644 index 000000000000..f55df0f2f081 --- /dev/null +++ b/ext/mbstring/tests/gh23106.phpt @@ -0,0 +1,22 @@ +--TEST-- +GH-23106 (mb_strpos() reads past the end of a haystack ending in a truncated UTF-8 sequence) +--EXTENSIONS-- +mbstring +--FILE-- +getMessage(), "\n"; +} +?> +--EXPECT-- +bool(false) +bool(false) +bool(false) +int(1) +mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)