Skip to content

Commit 0624eb4

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix GH-16184: UBSan address overflowed in ext/pcre/php_pcre.c
2 parents dbcc77d + 5839fc5 commit 0624eb4

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

ext/pcre/php_pcre.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,8 +1754,10 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, zend_string *su
17541754
}
17551755
if (preg_get_backref(&walk, &backref)) {
17561756
if (backref < count) {
1757-
match_len = offsets[(backref<<1)+1] - offsets[backref<<1];
1758-
walkbuf = zend_mempcpy(walkbuf, subject + offsets[backref << 1], match_len);
1757+
if (offsets[backref<<1] < SIZE_MAX) {
1758+
match_len = offsets[(backref<<1)+1] - offsets[backref<<1];
1759+
walkbuf = zend_mempcpy(walkbuf, subject + offsets[backref << 1], match_len);
1760+
}
17591761
}
17601762
continue;
17611763
}

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)