[php-src] PHP-8.4: Fix sparse set allocation size overflow (#23482)

From: Date: Tue, 08 Sep 2026 16:34:54 +0000
Subject: [php-src] PHP-8.4: Fix sparse set allocation size overflow (#23482)
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-141141@lists.php.net to get a copy of this message
Author: Georgij Tsarin (crystarm) Committer: Weilin Du (LamentXU123) Date: 2026-09-09T00:20:33+08:00 Commit: https://github.com/php/php-src/commit/7ef3bfec06c0ec580d074d4f102e4b91860ef497 Raw diff: https://github.com/php/php-src/commit/7ef3bfec06c0ec580d074d4f102e4b91860ef497.diff Fix sparse set allocation size overflow (#23482) Fix an integer-overflow risk when calculating the allocation size for IR sparse sets. Calculate the size separately and assert that multiplying by the element count did not overflow before allocating, while preserving the existing sparse/dense memory layout. This imports the final upstream IR fix. Closes #23482 Changed paths: M ext/opcache/jit/ir/ir_private.h Diff: diff --git a/ext/opcache/jit/ir/ir_private.h b/ext/opcache/jit/ir/ir_private.h index 3e1051ca3379..6d8f31a8b7ed 100644 --- a/ext/opcache/jit/ir/ir_private.h +++ b/ext/opcache/jit/ir/ir_private.h @@ -495,9 +495,12 @@ typedef struct _ir_sparse_set { IR_ALWAYS_INLINE void ir_sparse_set_init(ir_sparse_set *set, uint32_t size) { + size_t alloc_size = (size_t)size * 2 * sizeof(*set->data); + set->size = size; set->len = 0; - set->data = (uint32_t*)ir_mem_malloc(sizeof(uint32_t) * 2 * size) + size; + IR_ASSERT(!size || alloc_size / size == 2 * sizeof(*set->data)); + set->data = (uint32_t*)ir_mem_malloc(alloc_size) + size; #ifdef IR_DEBUG /* initialize sparse part to avoid valgrind warnings */ memset(&IR_SPARSE_SET_SPARSE(set, size - 1), 0, size * sizeof(uint32_t));

« previous php.cvs (#141141) next »