From ce8f7da49e2fea995993b49aa7a26f7640c2e258 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sun, 4 May 2025 21:40:33 +0900 Subject: [PATCH] [Bug #21304] Reload length and pointer after `#hash` method The receiver can be modified during the method calls. --- array.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/array.c b/array.c index b0a874bc83..59fc3422cf 100644 --- a/array.c +++ b/array.c @@ -5321,8 +5321,8 @@ rb_ary_eql(VALUE ary1, VALUE ary2) return rb_exec_recursive_paired(recursive_eql, ary1, ary2, ary2); } -VALUE -rb_ary_hash_values(long len, const VALUE *elements) +static VALUE +ary_hash_values(long len, const VALUE *elements, const VALUE ary) { long i; st_index_t h; @@ -5333,11 +5333,21 @@ rb_ary_hash_values(long len, const VALUE *elements) for (i=0; i integer @@ -5356,7 +5366,8 @@ rb_ary_hash_values(long len, const VALUE *elements) static VALUE rb_ary_hash(VALUE ary) { - return rb_ary_hash_values(RARRAY_LEN(ary), RARRAY_CONST_PTR(ary)); + RBIMPL_ASSERT_OR_ASSUME(ary); + return ary_hash_values(RARRAY_LEN(ary), RARRAY_CONST_PTR(ary), ary); } /*