[php-src] PHP-8.5: Merge branch 'PHP-8.4' into PHP-8.5
| From: | Weilin Du | Date: | Sat, 12 Sep 2026 06:43:11 +0000 |
| Subject: | [php-src] PHP-8.5: Merge branch 'PHP-8.4' into PHP-8.5 | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-141172@lists.php.net to get a copy of this message | ||
Author: Weilin Du (LamentXU123)
Date: 2026-09-12T14:29:29+08:00
Commit: https://github.com/php/php-src/commit/35889a78d804cf0b14b9fd3b113a2430fb00e2eb
Raw diff: https://github.com/php/php-src/commit/35889a78d804cf0b14b9fd3b113a2430fb00e2eb.diff
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
Fix GH-23106: mb_strpos() overreads truncated UTF-8 haystacks (#23107)
Changed paths:
A ext/mbstring/tests/gh23106.phpt
M NEWS
M ext/mbstring/mbstring.c
Diff:
diff --git a/NEWS b/NEWS
index 37f27f3572c3..8c4131fd6426 100644
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,10 @@ PHP NEWS
registrations are freed while still reachable from the cycle collector.
(Ilia Alshanetsky)
+- MBString:
+ . Fixed bug GH-23106 (mb_strpos() reads past the end of a haystack ending in
+ a truncated UTF-8 sequence). (Lazizbek Ergashev)
+
24 Sep 2026, PHP 8.5.11
diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c
index 0979231ef286..ccc4c3895d77 100644
--- a/ext/mbstring/mbstring.c
+++ b/ext/mbstring/mbstring.c
@@ -1897,6 +1897,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--
+<?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)