Repository navigation
Conversation
Data_Head() assumes the size field is the first member before the array data. dataheaphead had Heap first, so heap-flag checks and size reads got the heap pointer instead, and writes into memheap-backed empty arrays (e.g. mkclean's block SizeList) went past the static placeholder and corrupted memory. Put Size first to match datahead.
|
This is an independent fix for the same underlying bug as #219, with the same diagnosis: the 2025 refactor left One extra detail this approach needs and #219 does not: Verified with ASan: clean runs on mkclean and mkvalidator on files that segfault plain master. Happy to withdraw this in favor of #219 if the maintainers prefer that approach. |
corec: fix memory corruption from misaligned dataheaphead layout
The 2025 array refactor split the array header into two distinct layouts:
dataheadputsSizefirst, whiledataheapheadputHeapfirst andSizesecond.Because
Data_Head()always assumes the size field is the first memberbefore the array data, it incorrectly interpreted the
Heappointer ofheap-tracked arrays as the array size. This garbage size caused
ArrayResizeto skip proper reallocation and hand back the staticplaceholder in
MemHeap_Defaultas if it were writable storage.Consequently, writes into memheap-backed empty arrays (such as
mkclean'sblock
SizeList) went past the static placeholder and corrupted memory.This fix moves
Sizeto the first position indataheapheadto alignwith
datahead.This also fixes mkvalidator, which segfaults on any input with the broken
corec; verified before and after the fix.