Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ PHP NEWS
offset in a non-UTF-8 encoding). (Eyüp Can Akman)
. Fixed bug GH-21036 (mb_ereg_search_getregs() crashes after mb_eregi()
invalidates the regex cache). (Matthias Goergens)
. Fixed bug GH-23106 (mb_strpos() reads past the end of a haystack ending in
a truncated UTF-8 sequence). (Lazizbek Ergashev)

- Opcache:
. Fixed bug GH-22857 (Function JIT emits wrong code for FETCH_OBJ_FUNC_ARG on a
Expand Down
3 changes: 3 additions & 0 deletions ext/mbstring/mbstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -1891,6 +1891,9 @@ static unsigned char* offset_to_pointer_utf8(unsigned char *str, unsigned char *
}
pos += u8_tbl[*pos];
}
if (pos > end) {
pos = end;
}
return pos;
}
}
Expand Down
22 changes: 22 additions & 0 deletions ext/mbstring/tests/gh23106.phpt
Original file line number Diff line number Diff line change
@@ -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--
<?php
var_dump(mb_strpos("AA\xf0\x90", "xyz", 3));
var_dump(mb_strpos("AA\xf0\x90", "x", 3));
var_dump(mb_strrpos("AA\xf0\x90", "A", 3));
var_dump(mb_strrpos("AA\xf0\x90", "A", -1));
try {
mb_strpos("AA\xf0\x90", "xyz", 4);
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
bool(false)
bool(false)
bool(false)
int(1)
mb_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
Loading