diff --git a/NEWS b/NEWS index 1dfdb341fe1..d7ef5eddb87 100644 --- a/NEWS +++ b/NEWS @@ -58,6 +58,10 @@ PHP NEWS . Fixed bug GH-16009 (Segmentation fault with frameless functions and undefined CVs). (nielsdos) +- PCRE: + . Fixed bug GH-16184 (UBSan address overflowed in ext/pcre/php_pcre.c). + (nielsdos) + - PHPDBG: . Fixed bug GH-16181 (phpdbg: exit in exception handler reports fatal error). (cmb) diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index fcf4c45f26b..19068b90c0d 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -1754,8 +1754,10 @@ matched: } if (preg_get_backref(&walk, &backref)) { if (backref < count) { - match_len = offsets[(backref<<1)+1] - offsets[backref<<1]; - walkbuf = zend_mempcpy(walkbuf, subject + offsets[backref << 1], match_len); + if (offsets[backref<<1] < SIZE_MAX) { + match_len = offsets[(backref<<1)+1] - offsets[backref<<1]; + walkbuf = zend_mempcpy(walkbuf, subject + offsets[backref << 1], match_len); + } } continue; } diff --git a/ext/pcre/tests/gh16184.phpt b/ext/pcre/tests/gh16184.phpt new file mode 100644 index 00000000000..ba915d19af7 --- /dev/null +++ b/ext/pcre/tests/gh16184.phpt @@ -0,0 +1,13 @@ +--TEST-- +GH-16184 (UBSan address overflowed in ext/pcre/php_pcre.c) +--CREDITS-- +YuanchengJiang +--FILE-- + +--EXPECT-- +This test a string. It contains numbers * to 0* to 9* test well test parentheses and some other things*