From 9733304d6112ca3ac81b70dfecf7b2b7f63beff5 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Mon, 16 Dec 2024 10:49:49 -0500 Subject: [PATCH] Assert Ruby object in rb_gc_location rb_gc_location doesn't check that the object is actually a Ruby object and only checks if the object looks like a T_MOVED. This may have unexpected outcomes if the object is not a Ruby object (e.g. a piece of malloc memory may be corrupted). --- gc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gc.c b/gc.c index 9ee8714878..4c32c5a1ed 100644 --- a/gc.c +++ b/gc.c @@ -2427,6 +2427,8 @@ gc_location_internal(void *objspace, VALUE value) return value; } + GC_ASSERT(rb_gc_impl_pointer_to_heap_p(objspace, (void *)value)); + return rb_gc_impl_location(objspace, value); }