Skip to content

Commit ce8f7da

Browse files
authored
[Bug #21304] Reload length and pointer after #hash method
The receiver can be modified during the method calls.
1 parent 21035c8 commit ce8f7da

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

array.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5321,8 +5321,8 @@ rb_ary_eql(VALUE ary1, VALUE ary2)
53215321
return rb_exec_recursive_paired(recursive_eql, ary1, ary2, ary2);
53225322
}
53235323

5324-
VALUE
5325-
rb_ary_hash_values(long len, const VALUE *elements)
5324+
static VALUE
5325+
ary_hash_values(long len, const VALUE *elements, const VALUE ary)
53265326
{
53275327
long i;
53285328
st_index_t h;
@@ -5333,11 +5333,21 @@ rb_ary_hash_values(long len, const VALUE *elements)
53335333
for (i=0; i<len; i++) {
53345334
n = rb_hash(elements[i]);
53355335
h = rb_hash_uint(h, NUM2LONG(n));
5336+
if (ary) {
5337+
len = RARRAY_LEN(ary);
5338+
elements = RARRAY_CONST_PTR(ary);
5339+
}
53365340
}
53375341
h = rb_hash_end(h);
53385342
return ST2FIX(h);
53395343
}
53405344

5345+
VALUE
5346+
rb_ary_hash_values(long len, const VALUE *elements)
5347+
{
5348+
return ary_hash_values(len, elements, 0);
5349+
}
5350+
53415351
/*
53425352
* call-seq:
53435353
* hash -> integer
@@ -5356,7 +5366,8 @@ rb_ary_hash_values(long len, const VALUE *elements)
53565366
static VALUE
53575367
rb_ary_hash(VALUE ary)
53585368
{
5359-
return rb_ary_hash_values(RARRAY_LEN(ary), RARRAY_CONST_PTR(ary));
5369+
RBIMPL_ASSERT_OR_ASSUME(ary);
5370+
return ary_hash_values(RARRAY_LEN(ary), RARRAY_CONST_PTR(ary), ary);
53605371
}
53615372

53625373
/*

0 commit comments

Comments
 (0)