Skip to content

Commit

Permalink
Error on resource ID space overflow
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nikic committed Aug 31, 2021
1 parent edab9ad commit 501f1a4
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Zend/zend_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 501f1a4

Please sign in to comment.