Prevent overflow of length bits for embedded arrays

Embedded arrays only use 7 bits for the length, so it will overflow if
the GC can allocate large slots. We need to add the cap to ary_embeddable_p.
This commit is contained in:
Peter Zhu committed 2026-07-10 15:35:52 +09:00
1 parent 9eb455cdd1
commit 79da507032
1 file changed
+3 -1
Notes: git 2026-07-10 06:36:22 +00:00
+3 -1
View File
@@ -208,7 +208,9 @@ ary_embed_size(long capa)
static bool
ary_embeddable_p(long capa)
{
return rb_gc_size_allocatable_p(ary_embed_size(capa));
const long embed_len_max = RARRAY_EMBED_LEN_MASK >> RARRAY_EMBED_LEN_SHIFT;
return capa <= embed_len_max && rb_gc_size_allocatable_p(ary_embed_size(capa));
}
bool