Commit 4c4e4b747f4 for php
commit 4c4e4b747f4466a1993fd50b80e53ead6a3c1391
Author: Ilia Alshanetsky <ilia@ilia.ws>
Date: Sat Dec 5 17:51:18 2026 -0500
Zend: Accumulate parsed integer locally in _zend_handle_numeric_str_ex() (#25874)
_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.
diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c
index 59be1972cc4..d1a066101c6 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;
}