Skip to content

validate edge product in Mat_VarGetCells and Mat_VarGetStructs#318

Open
naruto-lgtm wants to merge 1 commit into
tbeu:masterfrom
naruto-lgtm:slab-getter-edge-overflow
Open

validate edge product in Mat_VarGetCells and Mat_VarGetStructs#318
naruto-lgtm wants to merge 1 commit into
tbeu:masterfrom
naruto-lgtm:slab-getter-edge-overflow

Conversation

@naruto-lgtm

Copy link
Copy Markdown
Contributor

Repro: Mat_VarGetCells on a rank-2 cell array with edge={3, 1431655766}.
Cause: N, the product of edge[], is accumulated in a signed int with no overflow guard. 3*1431655766 wraps to 2, so the pointer array is malloc'd for two cells while the copy loop still writes cells[0..2], one past the allocation (ASan heap-buffer-overflow in matvar_cell.c). Mat_VarGetStructs sizes its field array from the same unchecked product.
Fix: reject a negative edge or a product past INT_MAX before the allocation in both, matching CheckEdgeOverflow in the fixed-rank slab readers. Valid selections are unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant