libc: mspace realloc keeps only the requested bytes of a moved block (ProsperoEden launcher crash since #4407) #4879
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by David-cmrg on 2026-10-13T01:42:34Z.
Symptom
ProsperoEden (PPSA99008 v1.000.110, homebrew catalog) crashes about 5 s after opening its launcher on
main0c3dc9ca2(and on510a2188c), on Linux with llvmpipe. The crash is in its own code, on a pointer read from a heap object:0x0080000000000000in one run,0x0040000000000000in another.d53960612the launcher runs.510a2188cwith only #4407 reverted, the launcher runs again.Cause
sceLibcMspaceReallocandsceLibcMspaceReallocaligncopy the size a block was last requested with when they move it, not its usable size. A caller may use every bytesceLibcMspaceMallocUsableSizereports, and ProsperoEden does.Its per-thread cache of freed blocks bins blocks by usable size and hands one out for any request up to its bin (
headless/heap_arenas.inc: a request ofsbytes takes from binceil(s / 16)). A block allocated for 8 bytes, with a usable size of 32 since #4407, is handed out again for a 32-byte request. If that block is later grown byreallocand moved, only the original 8 bytes reach the new block.#4407 made this common, because a request of 1 to 16 bytes now has 32 usable bytes instead of 16. The copy itself predates #4407.
When dlmalloc's
mspace_reallochas to move a block, it copies the old chunk's usable size, bounded by the new size.Reproduce
In the mspace test, on
main0c3dc9ca2:sceLibcMspaceRealloc.Only the first byte arrives in the new block.
sceLibcMspaceReallocalignbehaves the same.