Skip to content

Commit 3b61eb6

Browse files
committed
rb_copy_generic_ivar avoid out of bound write
1 parent 81b7fd6 commit 3b61eb6

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

variable.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,8 +1719,8 @@ general_field_set_at(VALUE obj, rb_shape_t *target_shape, VALUE val, void *data,
17191719
attr_index_t index = target_shape->next_field_index - 1;
17201720
if (index >= current_shape->capacity) {
17211721
shape_resize_ivptr_func(obj, current_shape->capacity, target_shape->capacity, data);
1722+
set_shape_func(obj, target_shape, data);
17221723
}
1723-
set_shape_func(obj, target_shape, data);
17241724

17251725
VALUE *table = shape_ivptr_func(obj, data);
17261726
RB_OBJ_WRITE(obj, &table[index], val);
@@ -2315,7 +2315,7 @@ rb_copy_generic_ivar(VALUE dest, VALUE obj)
23152315
rb_shape_t *shape_to_set_on_dest = src_shape;
23162316
rb_shape_t *initial_shape = rb_shape_get_shape(dest);
23172317

2318-
if (initial_shape->heap_index != src_shape->heap_index || !rb_shape_canonical_p(src_shape)) {
2318+
if (!rb_shape_canonical_p(src_shape)) {
23192319
RUBY_ASSERT(initial_shape->type == SHAPE_ROOT);
23202320

23212321
shape_to_set_on_dest = rb_shape_rebuild_shape(initial_shape, src_shape);
@@ -2335,10 +2335,10 @@ rb_copy_generic_ivar(VALUE dest, VALUE obj)
23352335

23362336
if (src_shape->next_field_index == shape_to_set_on_dest->next_field_index) {
23372337
// Happy path, we can just memcpy the ivptr content
2338-
MEMCPY(dest_buf, src_buf, VALUE, src_num_ivs);
2338+
MEMCPY(dest_buf, src_buf, VALUE, shape_to_set_on_dest->next_field_index);
23392339

23402340
// Fire write barriers
2341-
for (uint32_t i = 0; i < src_num_ivs; i++) {
2341+
for (uint32_t i = 0; i < shape_to_set_on_dest->next_field_index; i++) {
23422342
RB_OBJ_WRITTEN(dest, Qundef, dest_buf[i]);
23432343
}
23442344
}

0 commit comments

Comments
 (0)