Skip to content

Commit f03e7c8

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix #74960: Heap buffer overflow via str_repeat
2 parents a9991fb + 760ff84 commit f03e7c8

File tree

3 files changed

+4
-1
lines changed

3 files changed

+4
-1
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ PHP NEWS
2727
. Fixed bug #72146 (Integer overflow on substr_replace). (cmb)
2828
. Fixed bug #81265 (getimagesize returns 0 for 256px ICO images).
2929
(George Dietrich)
30+
. Fixed bug #74960 (Heap buffer overflow via str_repeat). (cmb, Dmitry)
3031

3132
29 Jul 2021, PHP 8.0.9
3233

Zend/zend_operators.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1882,7 +1882,7 @@ ZEND_API zend_result ZEND_FASTCALL concat_function(zval *result, zval *op1, zval
18821882
size_t result_len = op1_len + op2_len;
18831883
zend_string *result_str;
18841884

1885-
if (UNEXPECTED(op1_len > SIZE_MAX - op2_len)) {
1885+
if (UNEXPECTED(op1_len > ZSTR_MAX_LEN - op2_len)) {
18861886
zend_throw_error(NULL, "String size overflow");
18871887
zval_ptr_dtor_str(&op1_copy);
18881888
zval_ptr_dtor_str(&op2_copy);

Zend/zend_string.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ END_EXTERN_C()
8383

8484
#define _ZSTR_STRUCT_SIZE(len) (_ZSTR_HEADER_SIZE + len + 1)
8585

86+
#define ZSTR_MAX_LEN (SIZE_MAX - ZEND_MM_ALIGNED_SIZE(_ZSTR_HEADER_SIZE + 1))
87+
8688
#define ZSTR_ALLOCA_ALLOC(str, _len, use_heap) do { \
8789
(str) = (zend_string *)do_alloca(ZEND_MM_ALIGNED_SIZE_EX(_ZSTR_STRUCT_SIZE(_len), 8), (use_heap)); \
8890
GC_SET_REFCOUNT(str, 1); \

0 commit comments

Comments
 (0)