[Bugfix] EntityCollection extended slice assignment skips gridstate resize #263

Closed
opened 2026-03-07 23:19:41 +00:00 by john · 0 comments
Owner

Summary

UIEntityCollection::ass_subscript() for extended slice assignment (grid.entities[0:4:2] = [entity_a, entity_b]) sets entity grid pointers but never initializes or resizes gridstate.

Root Cause

UIEntityCollection.cpp:519-524:

*cur_it = new_items[new_idx++];
(*cur_it)->grid = self->grid;

if (self->grid) {
    self->grid->spatial_hash.insert(*cur_it);
}
// BUG: No gridstate initialization or resize

Reproduction

import mcrfpy

small_grid = mcrfpy.Grid(grid_size=(10, 10))
large_grid = mcrfpy.Grid(grid_size=(50, 50))

p1 = mcrfpy.Entity((0, 0))
p2 = mcrfpy.Entity((1, 1))
p3 = mcrfpy.Entity((2, 2))
p4 = mcrfpy.Entity((3, 3))
large_grid.entities.extend([p1, p2, p3, p4])

e1 = mcrfpy.Entity((5, 5))
e2 = mcrfpy.Entity((6, 6))
small_grid.entities.extend([e1, e2])
e1.update_visibility()  # gridstate = 100
e2.update_visibility()  # gridstate = 100

large_grid.entities[0:4:2] = [e1, e2]  # BUG: no gridstate resize
e1.update_visibility()  # heap overflow

Fix

Add gridstate resize after setting the grid reference in the extended slice assignment path.

Severity

Critical — heap buffer overflow, same class as the set_grid() bug fixed during 7DRL 2026.

## Summary `UIEntityCollection::ass_subscript()` for extended slice assignment (`grid.entities[0:4:2] = [entity_a, entity_b]`) sets entity grid pointers but never initializes or resizes gridstate. ## Root Cause `UIEntityCollection.cpp:519-524`: ```cpp *cur_it = new_items[new_idx++]; (*cur_it)->grid = self->grid; if (self->grid) { self->grid->spatial_hash.insert(*cur_it); } // BUG: No gridstate initialization or resize ``` ## Reproduction ```python import mcrfpy small_grid = mcrfpy.Grid(grid_size=(10, 10)) large_grid = mcrfpy.Grid(grid_size=(50, 50)) p1 = mcrfpy.Entity((0, 0)) p2 = mcrfpy.Entity((1, 1)) p3 = mcrfpy.Entity((2, 2)) p4 = mcrfpy.Entity((3, 3)) large_grid.entities.extend([p1, p2, p3, p4]) e1 = mcrfpy.Entity((5, 5)) e2 = mcrfpy.Entity((6, 6)) small_grid.entities.extend([e1, e2]) e1.update_visibility() # gridstate = 100 e2.update_visibility() # gridstate = 100 large_grid.entities[0:4:2] = [e1, e2] # BUG: no gridstate resize e1.update_visibility() # heap overflow ``` ## Fix Add gridstate resize after setting the grid reference in the extended slice assignment path. ## Severity **Critical** — heap buffer overflow, same class as the set_grid() bug fixed during 7DRL 2026.
john closed this issue 2026-03-14 06:25:16 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
john/McRogueFace#263
No description provided.