Skip to content

Commit edbd9ed

Browse files
committed
variable.c: avoid out of bound write in generic_field_set
[Bug #21445]
1 parent 0cec4a1 commit edbd9ed

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

test/ruby/test_object_id.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ def test_marshal_with_id_and_ivar_and_frozen
115115
assert_equal 42, copy.instance_variable_get(:@foo)
116116
refute_predicate copy, :frozen?
117117
end
118+
119+
def test_object_id_need_resize
120+
(3 - @obj.instance_variables.size).times do |i|
121+
@obj.instance_variable_set("@a_#{i}", "[Bug #21445]")
122+
end
123+
@obj.object_id
124+
GC.start
125+
end
118126
end
119127

120128
class TestObjectIdClass < TestObjectId

variable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1922,7 +1922,7 @@ generic_field_set(VALUE obj, shape_id_t target_shape_id, VALUE val)
19221922
else {
19231923
attr_index_t index = RSHAPE_INDEX(target_shape_id);
19241924
if (index >= RSHAPE_CAPACITY(current_shape_id)) {
1925-
fields_obj = rb_imemo_fields_new(rb_obj_class(obj), index);
1925+
fields_obj = rb_imemo_fields_new(rb_obj_class(obj), RSHAPE_CAPACITY(target_shape_id));
19261926
if (original_fields_obj) {
19271927
attr_index_t fields_count = RSHAPE_LEN(current_shape_id);
19281928
VALUE *fields = rb_imemo_fields_ptr(fields_obj);

0 commit comments

Comments
 (0)