libc: mspace realloc keeps only the requested bytes of a moved block (ProsperoEden launcher crash since #4407) #4879

Closed
opened 2026-10-13 01:42:34 +00:00 by David-cmrg · 0 comments
David-cmrg commented 2026-10-13 01:42:34 +00:00 (Migrated from github.com)
Contributor

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 main 0c3dc9ca2 (and on 510a2188c), on Linux with llvmpipe. The crash is in its own code, on a pointer read from a heap object: 0x0080000000000000 in one run, 0x0040000000000000 in another.

  • On d53960612 the launcher runs.
  • On 510a2188c with only #4407 reverted, the launcher runs again.
  • #4852 reports a crash at the same point on Windows, on its GL thread.

Cause

sceLibcMspaceRealloc and sceLibcMspaceReallocalign copy the size a block was last requested with when they move it, not its usable size. A caller may use every byte sceLibcMspaceMallocUsableSize reports, 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 of s bytes takes from bin ceil(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 by realloc and 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_realloc has to move a block, it copies the old chunk's usable size, bounded by the new size.

Reproduce

In the mspace test, on main 0c3dc9ca2:

  1. Allocate 1 byte and write all of its usable bytes.
  2. Allocate a second block right behind it.
  3. Grow the first block to 4096 bytes with sceLibcMspaceRealloc.

Only the first byte arrives in the new block. sceLibcMspaceReallocalign behaves the same.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5823058137 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/4879). Originally posted by [David-cmrg](https://github.com/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 `main` `0c3dc9ca2` (and on `510a2188c`), on Linux with llvmpipe. The crash is in its own code, on a pointer read from a heap object: `0x0080000000000000` in one run, `0x0040000000000000` in another. - On `d53960612` the launcher runs. - On `510a2188c` with only #4407 reverted, the launcher runs again. - #4852 reports a crash at the same point on Windows, on its GL thread. ### Cause `sceLibcMspaceRealloc` and `sceLibcMspaceReallocalign` copy the size a block was last requested with when they move it, not its usable size. A caller may use every byte `sceLibcMspaceMallocUsableSize` reports, 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 of `s` bytes takes from bin `ceil(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 by `realloc` and 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_realloc` has to move a block, it copies the old chunk's usable size, bounded by the new size. ### Reproduce In the mspace test, on `main` `0c3dc9ca2`: 1. Allocate 1 byte and write all of its usable bytes. 2. Allocate a second block right behind it. 3. Grow the first block to 4096 bytes with `sceLibcMspaceRealloc`. Only the first byte arrives in the new block. `sceLibcMspaceReallocalign` behaves the same.
Sign in to join this conversation.
No labels
No milestone
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.

Reference
boykopovar/AnyPS5#4879
No description provided.