Skip to content

Commit 9f18bff

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Fix #74960: Heap buffer overflow via str_repeat
2 parents 9108ac6 + f03e7c8 commit 9f18bff

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

Zend/zend_operators.c

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

1921-
if (UNEXPECTED(op1_len > SIZE_MAX - op2_len)) {
1921+
if (UNEXPECTED(op1_len > ZSTR_MAX_LEN - op2_len)) {
19221922
zend_throw_error(NULL, "String size overflow");
19231923
zval_ptr_dtor_str(&op1_copy);
19241924
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)