fix(libc): support large collate transform results #1708

Closed
gdrosa wants to merge 1 commit from upstream-pr/1708 into main
gdrosa commented 2026-10-08 17:13:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gdrosa on 2026-10-08T17:13:50Z.


What

collate<char>::do_transform currently throws for every input of 4095 characters or more because the returned guest string requires a large-allocation header. Support those results by keeping the original allocation pointer immediately before a 32-byte-aligned data pointer, and reject allocation-size overflow before reading input or allocating. Small strings use the existing path.

The string layout and guest deallocation rule come from #885. Alignment and allocation padding follow Microsoft STL (_Allocate_manually_vector_aligned); they have not been measured on a PS5, which remains recorded in TechnicalDebt. Embedded NULs and non-C locales still throw.

The change modifies only LocaleSupport.cpp, its existing GuestCollate.cpp regression, and the corresponding debt entry. It is independent of #1614 and #1498.

Tested

Windows x64, Release, portable MinGW-w64 GCC 15.2.0, CMake/Ninja from the existing virtualenv, SPIRV-Tools disabled:

  • Complete libc build and 34/34 component CTests pass before and after the patch.
  • A standalone PoC against the real DLL exercises 576 cases and 76,769 checks: 416 rejected cases on main, zero failures with the fix. It covers the 4094/4095 boundary, strings up to 65,536 bytes, all 32 base-address residues, preserved input and output guards, freeing through the guest allocation pointer, failed allocation, guarded input pages, and concurrent calls.
  • Existing regression covers inline strings and 4094-byte heap strings; new cases cover 4095, 4096 and 65536 bytes, the allocation header, alignment and content.
  • Reviewed file lists for 375 open PRs and the complete relevant diffs. #1614 changes character conversions; #1498 adds wide collation; #545 adds re-exports; #1128 reformats existing code. None implements this allocation path.

Ubuntu 24.04 x86-64, GCC 13.3.0, CMake/Ninja in a virtualenv: 37/37 libc CTests pass with zero skips. The same standalone allocation PoC passes all 576 cases and 76,769 checks; the test-registration check passes. Independent Linux run checks out the exact contribution commit caba31b731272bafb854a5d6e2134657c6ef1d5e. Guard-page input checks in that PoC run on Windows; Linux uses the canary checks.

Console execution and in-game behavior are unverified.

Complete Windows project build and libs target completed. Full CTest: 457 tests, 0 failures, 0 errors, 0 skips.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; silent stubs are listed in TechnicalDebt
  • No notes, investigation files or images added to the repository
  • New third-party code is a submodule built from source: none added
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4790329384 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1708). Originally posted by [gdrosa](https://github.com/gdrosa) on 2026-10-08T17:13:50Z. --- ### What `collate<char>::do_transform` currently throws for every input of 4095 characters or more because the returned guest string requires a large-allocation header. Support those results by keeping the original allocation pointer immediately before a 32-byte-aligned data pointer, and reject allocation-size overflow before reading input or allocating. Small strings use the existing path. The string layout and guest deallocation rule come from #885. Alignment and allocation padding follow [Microsoft STL](https://github.com/microsoft/STL/blob/main/stl/inc/xmemory) (`_Allocate_manually_vector_aligned`); they have not been measured on a PS5, which remains recorded in TechnicalDebt. Embedded NULs and non-C locales still throw. The change modifies only `LocaleSupport.cpp`, its existing `GuestCollate.cpp` regression, and the corresponding debt entry. It is independent of #1614 and #1498. ### Tested Windows x64, Release, portable MinGW-w64 GCC 15.2.0, CMake/Ninja from the existing virtualenv, SPIRV-Tools disabled: - Complete libc build and 34/34 component CTests pass before and after the patch. - A standalone PoC against the real DLL exercises 576 cases and 76,769 checks: 416 rejected cases on main, zero failures with the fix. It covers the 4094/4095 boundary, strings up to 65,536 bytes, all 32 base-address residues, preserved input and output guards, freeing through the guest allocation pointer, failed allocation, guarded input pages, and concurrent calls. - Existing regression covers inline strings and 4094-byte heap strings; new cases cover 4095, 4096 and 65536 bytes, the allocation header, alignment and content. - Reviewed file lists for 375 open PRs and the complete relevant diffs. #1614 changes character conversions; #1498 adds wide collation; #545 adds re-exports; #1128 reformats existing code. None implements this allocation path. Ubuntu 24.04 x86-64, GCC 13.3.0, CMake/Ninja in a virtualenv: 37/37 libc CTests pass with zero skips. The same standalone allocation PoC passes all 576 cases and 76,769 checks; the test-registration check passes. [Independent Linux run](https://github.com/gdrosa/AnyPS5/actions/runs/37814529505) checks out the exact contribution commit `caba31b731272bafb854a5d6e2134657c6ef1d5e`. Guard-page input checks in that PoC run on Windows; Linux uses the canary checks. Console execution and in-game behavior are unverified. Complete Windows project build and `libs` target completed. Full CTest: 457 tests, 0 failures, 0 errors, 0 skips. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; silent stubs are listed in TechnicalDebt - [x] No notes, investigation files or images added to the repository - [x] New third-party code is a submodule built from source: none added - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-08 17:26:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T17:26:32Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#1711 docs/dev/TechnicalDebt.md L341
#1727 docs/dev/TechnicalDebt.md L341
#1832 docs/dev/TechnicalDebt.md L341-342
#1982 docs/dev/TechnicalDebt.md L341
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6065394394 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1708#issuecomment-6065394394). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-08T17:26:32Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #1711 | `docs/dev/TechnicalDebt.md` [L341](https://github.com/boykopovar/AnyPS5/blob/f145139676a48306681d3a4d5fabf83938759daf/docs/dev/TechnicalDebt.md#L341) | | | | #1727 | `docs/dev/TechnicalDebt.md` [L341](https://github.com/boykopovar/AnyPS5/blob/f145139676a48306681d3a4d5fabf83938759daf/docs/dev/TechnicalDebt.md#L341) | | | | #1832 | `docs/dev/TechnicalDebt.md` [L341-342](https://github.com/boykopovar/AnyPS5/blob/f145139676a48306681d3a4d5fabf83938759daf/docs/dev/TechnicalDebt.md#L341-L342) | | | | #1982 | `docs/dev/TechnicalDebt.md` [L341](https://github.com/boykopovar/AnyPS5/blob/f145139676a48306681d3a4d5fabf83938759daf/docs/dev/TechnicalDebt.md#L341) | | |
oneandonlydean commented 2026-10-09 08:55:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T08:55:20Z.


Closing: no title is shown to reach collate::transform with 4095 or more characters on main, where it throws today, and the allocation layout is unmeasured on PS5. Please reopen with the title ID and the log line if one does.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6077713866 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1708#issuecomment-6077713866). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T08:55:20Z. --- Closing: no title is shown to reach `collate::transform` with 4095 or more characters on main, where it throws today, and the allocation layout is unmeasured on PS5. Please reopen with the title ID and the log line if one does.

Pull request closed

Sign in to join this conversation.
No reviewers
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!1708
No description provided.