From 8aa2322bb77120ab39ee63dd27b2d17c60f919ff Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Thu, 9 Apr 2026 13:23:06 -0700 Subject: Add slot size assertion to ar_force_convert_table Co-authored-by: Luke Gruber Co-authored-by: Matt Valentine-House --- hash.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hash.c b/hash.c index 700c429d2a..8507c9c8f5 100644 --- a/hash.c +++ b/hash.c @@ -604,6 +604,7 @@ RHASH_AR_TABLE_SIZE_DEC(VALUE h) static inline void RHASH_AR_TABLE_CLEAR(VALUE h) { + RUBY_ASSERT(rb_gc_obj_slot_size(h) >= sizeof(struct RHash) + sizeof(ar_table)); RBASIC(h)->flags &= ~RHASH_AR_TABLE_SIZE_MASK; RBASIC(h)->flags &= ~RHASH_AR_TABLE_BOUND_MASK; @@ -719,6 +720,8 @@ ar_force_convert_table(VALUE hash, const char *file, int line) st_hash_t hashes[RHASH_AR_TABLE_MAX_SIZE]; unsigned int bound, size; + RUBY_ASSERT(rb_gc_obj_slot_size(hash) >= sizeof(struct RHash) + sizeof(ar_table)); + // prepare hash values do { st_data_t keys[RHASH_AR_TABLE_MAX_SIZE]; -- cgit v1.2.3