[php-src] master: Merge branch 'PHP-8.5'
| From: | Weilin Du | Date: | Sat, 12 Sep 2026 06:43:11 +0000 |
| Subject: | [php-src] master: Merge branch 'PHP-8.5' | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-141173@lists.php.net to get a copy of this message | ||
Author: Weilin Du (LamentXU123)
Date: 2026-09-12T14:32:08+08:00
Commit: https://github.com/php/php-src/commit/063d7875422db080bde510ba1b909b038993e1a0
Raw diff: https://github.com/php/php-src/commit/063d7875422db080bde510ba1b909b038993e1a0.diff
Merge branch 'PHP-8.5'
* PHP-8.5:
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 1212b4fae181..5182713edfc5 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)
+
- SPL:
. Fixed bug GH-23385 (SplDoublyLinkedList::serialize() use-after-free when
__serialize() removes an element). (David Carlier)
diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c
index 4059d8d35fd1..ed3e8bd1cf44 100644
--- a/ext/mbstring/mbstring.c
+++ b/ext/mbstring/mbstring.c
@@ -1902,6 +1902,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)