[Bugfix] EntityCollection contiguous slice assignment skips gridstate resize #262

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

Summary

UIEntityCollection::ass_subscript() for contiguous slice assignment (grid.entities[1:3] = [entity_a]) sets entity grid pointers but never initializes or resizes gridstate.

Root Cause

UIEntityCollection.cpp:492-498:

// Insert new items
for (const auto& entity : new_items) {
    self->data->insert(insert_pos, entity);
    entity->grid = self->grid;
    if (self->grid) {
        self->grid->spatial_hash.insert(entity);
    }
    // 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))

placeholder1 = mcrfpy.Entity((0, 0))
placeholder2 = mcrfpy.Entity((1, 1))
large_grid.entities.append(placeholder1)
large_grid.entities.append(placeholder2)

entity = mcrfpy.Entity((5, 5))
small_grid.entities.append(entity)
entity.update_visibility()  # gridstate = 100 entries

large_grid.entities[0:2] = [entity]  # BUG: no gridstate resize
entity.update_visibility()  # heap overflow

Fix

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

Severity

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

## Summary `UIEntityCollection::ass_subscript()` for contiguous slice assignment (`grid.entities[1:3] = [entity_a]`) sets entity grid pointers but never initializes or resizes gridstate. ## Root Cause `UIEntityCollection.cpp:492-498`: ```cpp // Insert new items for (const auto& entity : new_items) { self->data->insert(insert_pos, entity); entity->grid = self->grid; if (self->grid) { self->grid->spatial_hash.insert(entity); } // 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)) placeholder1 = mcrfpy.Entity((0, 0)) placeholder2 = mcrfpy.Entity((1, 1)) large_grid.entities.append(placeholder1) large_grid.entities.append(placeholder2) entity = mcrfpy.Entity((5, 5)) small_grid.entities.append(entity) entity.update_visibility() # gridstate = 100 entries large_grid.entities[0:2] = [entity] # BUG: no gridstate resize entity.update_visibility() # heap overflow ``` ## Fix Add gridstate resize after setting the grid reference in the contiguous 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#262
No description provided.