Skip to content

Commit 549a30d

Browse files
committed
Fix out of bounds access in gc_find_additional_buffer()
1 parent 648b756 commit 549a30d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Zend/zend_gc.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,12 @@ static zend_always_inline gc_root_buffer* gc_find_additional_buffer(zend_refcoun
275275

276276
/* We have to check each additional_buffer to find which one holds the ref */
277277
while (additional_buffer) {
278-
gc_root_buffer *root = additional_buffer->buf + (GC_ADDRESS(GC_INFO(ref)) - GC_ROOT_BUFFER_MAX_ENTRIES);
279-
if (root->ref == ref) {
280-
return root;
278+
uint32_t idx = GC_ADDRESS(GC_INFO(ref)) - GC_ROOT_BUFFER_MAX_ENTRIES;
279+
if (idx < additional_buffer->used) {
280+
gc_root_buffer *root = additional_buffer->buf + idx;
281+
if (root->ref == ref) {
282+
return root;
283+
}
281284
}
282285
additional_buffer = additional_buffer->next;
283286
}

0 commit comments

Comments
 (0)