Skip to content

Commit ddc7a6b

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Fix phpGH-16184: UBSan address overflowed in ext/pcre/php_pcre.c
2 parents d4a4d2e + c4bb075 commit ddc7a6b

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

NEWS

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ PHP NEWS
4040
. Fixed stub for openssl_csr_new. (Jakub Zelenka)
4141

4242
- PCRE:
43-
. Fixed GH-16189 (underflow on offset argument). (David Carlier)
43+
. Fixed bug GH-16189 (underflow on offset argument). (David Carlier)
44+
. Fixed bug GH-16184 (UBSan address overflowed in ext/pcre/php_pcre.c).
45+
(nielsdos)
4446

4547
- PHPDBG:
4648
. Fixed bug GH-15901 (phpdbg: Assertion failure on i funcs). (cmb)

ext/pcre/php_pcre.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,9 +1728,11 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, zend_string *su
17281728
}
17291729
if (preg_get_backref(&walk, &backref)) {
17301730
if (backref < count) {
1731-
match_len = offsets[(backref<<1)+1] - offsets[backref<<1];
1732-
memcpy(walkbuf, subject + offsets[backref<<1], match_len);
1733-
walkbuf += match_len;
1731+
if (offsets[backref<<1] < SIZE_MAX) {
1732+
match_len = offsets[(backref<<1)+1] - offsets[backref<<1];
1733+
memcpy(walkbuf, subject + offsets[backref<<1], match_len);
1734+
walkbuf += match_len;
1735+
}
17341736
}
17351737
continue;
17361738
}

ext/pcre/tests/gh16184.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
GH-16184 (UBSan address overflowed in ext/pcre/php_pcre.c)
3+
--CREDITS--
4+
YuanchengJiang
5+
--FILE--
6+
<?php
7+
8+
$string = 'This is a string. It contains numbers (0*9) as well as parentheses and some other things!';
9+
echo preg_replace(array('/\b\w{1}s/', '/(\d{1})*(\d{1})/', '/[\(!\)]/'), array('test', '$1 to $2', '*'), $string), "\n";
10+
11+
?>
12+
--EXPECT--
13+
This test a string. It contains numbers * to 0* to 9* test well test parentheses and some other things*

0 commit comments

Comments
 (0)