From 7225441e2c1b5ad81e21d7e63777f4b9e375d8f0 Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Sat, 28 Nov 2026 10:25:00 -0500 Subject: [PATCH] Zend: Accumulate parsed integer locally in _zend_handle_numeric_str_ex() _zend_handle_numeric_str_ex() updated *idx on every digit. Because key is a const char * that may alias *idx, GCC loaded and stored *idx on every loop iteration. Accumulate into a local zend_ulong and store *idx once at the end of the string. --- Zend/zend_hash.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c index 59be1972cc44..d1a066101c63 100644 --- a/Zend/zend_hash.c +++ b/Zend/zend_hash.c @@ -3490,22 +3490,23 @@ ZEND_ATTRIBUTE_NONNULL ZEND_API bool ZEND_FASTCALL _zend_handle_numeric_str_ex(c *tmp > '2')) { /* overflow */ return 0; } - *idx = (*tmp - '0'); + zend_ulong val = *tmp - '0'; while (1) { ++tmp; if (tmp == end) { if (*key == '-') { - if (*idx-1 > ZEND_LONG_MAX) { /* overflow */ + if (val-1 > ZEND_LONG_MAX) { /* overflow */ return 0; } - *idx = 0 - *idx; - } else if (*idx > ZEND_LONG_MAX) { /* overflow */ + val = 0 - val; + } else if (val > ZEND_LONG_MAX) { /* overflow */ return 0; } + *idx = val; return 1; } if (*tmp <= '9' && *tmp >= '0') { - *idx = (*idx * 10) + (*tmp - '0'); + val = (val * 10) + (*tmp - '0'); } else { return 0; }