From 501f1a45f538350ca907bb41fb51a7edbd041e19 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 30 Aug 2021 16:31:28 +0200 Subject: [PATCH] Error on resource ID space overflow When more than INT_MAX resource are created, throw a fatal error, rather than reusing already allocated IDs, which will result in assertion failures or crashes down the line. This doesn't fix the fundamental problem, but makes the failure more graceful with an obvious cause. Inspired by https://bugs.php.net/bug.php?id=81399. Closes GH-7428. --- Zend/zend_list.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Zend/zend_list.c b/Zend/zend_list.c index 21d013a5895..521b34ffa40 100644 --- a/Zend/zend_list.c +++ b/Zend/zend_list.c @@ -37,6 +37,8 @@ ZEND_API zval* ZEND_FASTCALL zend_list_insert(void *ptr, int type) index = zend_hash_next_free_element(&EG(regular_list)); if (index == 0) { index = 1; + } else if (index == INT_MAX) { + zend_error_noreturn(E_ERROR, "Resource ID space overflow"); } ZVAL_NEW_RES(&zv, index, ptr, type); return zend_hash_index_add_new(&EG(regular_list), index, &zv);