Skip to content

Commit d246b36

Browse files
Indra-dbSanderMertens
authored andcommitted
#1176 Fix memory out of bounds memory write when bulk overriding components
without this fix, the newly introduced test case would segfault. This bug happens due to the fact that in C you loop count times, but also offset the dest_ptr, and then within the copy impl of C++, it loops count again, this means you would go count-1 * size_obj out of memory bounds for src as well as dest ptr. This fix is the correct fix as it limits src ptr to just 1, while the dest ptr still gets offset each iteration. (this was previously discussed with sanders, the information above is just for tracking why & what)
1 parent 87f9ae6 commit d246b36

File tree

5 files changed

+99
-44
lines changed

5 files changed

+99
-44
lines changed

flecs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15148,7 +15148,7 @@ void flecs_override_copy(
1514815148
int32_t i;
1514915149
if (copy) {
1515015150
for (i = 0; i < count; i ++) {
15151-
copy(ptr, src, count, ti);
15151+
copy(ptr, src, 1, ti);
1515215152
ptr = ECS_OFFSET(ptr, size);
1515315153
}
1515415154
} else {

src/observable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ void flecs_override_copy(
500500
int32_t i;
501501
if (copy) {
502502
for (i = 0; i < count; i ++) {
503-
copy(ptr, src, count, ti);
503+
copy(ptr, src, 1, ti);
504504
ptr = ECS_OFFSET(ptr, size);
505505
}
506506
} else {

test/api/project.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,8 @@
10681068
"on_set_hook_on_override",
10691069
"on_set_hook_on_auto_override",
10701070
"batched_set_new_component_w_lifecycle",
1071-
"batched_ensure_new_component_w_lifecycle"
1071+
"batched_ensure_new_component_w_lifecycle",
1072+
"on_nested_prefab_copy_test_invokes_copy_count"
10721073
]
10731074
}, {
10741075
"id": "Sorting",

0 commit comments

Comments
 (0)