Skip to content

Commit 2a6ec7d

Browse files
committed
rb_copy_generic_ivar avoid out of bound write
1 parent 3485fdc commit 2a6ec7d

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

variable.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,6 +1719,7 @@ 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_fields_func(obj, current_shape->capacity, target_shape->capacity, data);
1722+
set_shape_func(obj, target_shape, data);
17221723
}
17231724

17241725
if (target_shape->next_field_index > current_shape->next_field_index) {
@@ -2318,7 +2319,7 @@ rb_copy_generic_ivar(VALUE dest, VALUE obj)
23182319
rb_shape_t *shape_to_set_on_dest = src_shape;
23192320
rb_shape_t *initial_shape = rb_shape_get_shape(dest);
23202321

2321-
if (initial_shape->heap_index != src_shape->heap_index || !rb_shape_canonical_p(src_shape)) {
2322+
if (!rb_shape_canonical_p(src_shape)) {
23222323
RUBY_ASSERT(initial_shape->type == SHAPE_ROOT);
23232324

23242325
shape_to_set_on_dest = rb_shape_rebuild_shape(initial_shape, src_shape);
@@ -2338,10 +2339,10 @@ rb_copy_generic_ivar(VALUE dest, VALUE obj)
23382339

23392340
if (src_shape->next_field_index == shape_to_set_on_dest->next_field_index) {
23402341
// Happy path, we can just memcpy the ivptr content
2341-
MEMCPY(dest_buf, src_buf, VALUE, src_num_ivs);
2342+
MEMCPY(dest_buf, src_buf, VALUE, shape_to_set_on_dest->next_field_index);
23422343

23432344
// Fire write barriers
2344-
for (uint32_t i = 0; i < src_num_ivs; i++) {
2345+
for (uint32_t i = 0; i < shape_to_set_on_dest->next_field_index; i++) {
23452346
RB_OBJ_WRITTEN(dest, Qundef, dest_buf[i]);
23462347
}
23472348
}

0 commit comments

Comments
 (0)