fix(libc): reject oversized snprintf buffers on Windows #5070

Closed
MarcZX10 wants to merge 3 commits from upstream-pr/5070 into main
MarcZX10 commented 2026-10-13 10:31:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T10:31:40Z.


What

Carries Hussein Kadhim's two original commits for #3974, preserving his author attribution. On Windows, snprintf and vsnprintf now return -1 with EOVERFLOW and clear a non-null destination when the buffer size exceeds INT_MAX + 1; the exact INT_MAX + 1 boundary still works. Adds regression coverage for oversized sizes, SIZE_MAX, null buffers, and the boundary. A separate MarcZX100 test commit keeps these cases away from the test hunk changed by #4995.

Tested

  • Linux, GCC 12.2, Release: built guest_formatting_tests; ctest -R '^guest_formatting$' passed (1/1). Linux excludes the Windows-only size checks.
  • MinGW-w64 GCC 12 syntax-only checks passed for Formatting.cpp and tests/Formatting.cpp. A full Windows build could not run: this host's MinGW selects SjLj exceptions, while AnyPS5 requires the WinLibs DWARF toolchain.
  • The issue author reports that the added boundary cases passed on Windows 11 with WinLibs MinGW GCC 15.2 on the original base (a11c8f7f). That report is from the issue, not a run of this current-main rebase.
  • python3 tools/check_conventions.py --base upstream/main and git diff --check passed. No title run was performed.

Checklist

  • Based on current main; no open PR implements the same size-limit behavior
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); no new stubs added
  • No notes, investigation files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behavior, not title-specific
  • Depends on: #4981 (merge-order proposal only; the current branches conflict in docs/dev/debt/libc.md; the author confirmed the order works; rebase again after #4981 merges)
  • Unblocks: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4841891747 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5070). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T10:31:40Z. --- ### What Carries Hussein Kadhim's two original commits for #3974, preserving his author attribution. On Windows, `snprintf` and `vsnprintf` now return -1 with `EOVERFLOW` and clear a non-null destination when the buffer size exceeds `INT_MAX + 1`; the exact `INT_MAX + 1` boundary still works. Adds regression coverage for oversized sizes, `SIZE_MAX`, null buffers, and the boundary. A separate MarcZX100 test commit keeps these cases away from the test hunk changed by #4995. ### Tested - Linux, GCC 12.2, Release: built `guest_formatting_tests`; `ctest -R '^guest_formatting$'` passed (1/1). Linux excludes the Windows-only size checks. - MinGW-w64 GCC 12 syntax-only checks passed for `Formatting.cpp` and `tests/Formatting.cpp`. A full Windows build could not run: this host's MinGW selects SjLj exceptions, while AnyPS5 requires the WinLibs DWARF toolchain. - The issue author reports that the added boundary cases passed on Windows 11 with WinLibs MinGW GCC 15.2 on the original base (`a11c8f7f`). That report is from the issue, not a run of this current-main rebase. - `python3 tools/check_conventions.py --base upstream/main` and `git diff --check` passed. No title run was performed. ### Checklist - [x] Based on current `main`; no open PR implements the same size-limit behavior - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); no new stubs added - [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 behavior, not title-specific - [x] Depends on: #4981 (merge-order proposal only; the current branches conflict in `docs/dev/debt/libc.md`; the author confirmed the order works; rebase again after #4981 merges) - [x] Unblocks: none - [x] AI-assisted: yes
xXPBSXx commented 2026-10-13 11:13:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T11:13:16Z.


Review note (static): the check matches FreeBSD 11.4 vsnprintf.c: after the size is reduced by one for the terminator, n > INT_MAX sets EOVERFLOW, writes *str = 0 and returns EOF, and n == 0 is not an error, which is what size - 1 > INT_MAX with the size == 0 early return does. Two open points: (1) the Windows block CheckWindowsSizeLimits has not been run on Windows by the author (the description says only a syntax-only MinGW check and a Linux run, and the Windows report is from the original base); we can run guest_formatting on Windows 10 with the current head if that helps. (2) The description says the branch conflicts with #4981 in docs/dev/debt/libc.md; whichever lands second needs that rebase.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6144279515 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5070#issuecomment-6144279515). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-13T11:13:16Z. --- Review note (static): the check matches FreeBSD 11.4 `vsnprintf.c`: after the size is reduced by one for the terminator, `n > INT_MAX` sets `EOVERFLOW`, writes `*str = 0` and returns `EOF`, and `n == 0` is not an error, which is what `size - 1 > INT_MAX` with the `size == 0` early return does. Two open points: (1) the Windows block `CheckWindowsSizeLimits` has not been run on Windows by the author (the description says only a syntax-only MinGW check and a Linux run, and the Windows report is from the original base); we can run `guest_formatting` on Windows 10 with the current head if that helps. (2) The description says the branch conflicts with #4981 in `docs/dev/debt/libc.md`; whichever lands second needs that rebase. AI-assisted (Claude Code).
likecrank-dotcom commented 2026-10-13 14:03:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by likecrank-dotcom on 2026-10-13T14:03:27Z.


Independent Windows verification of current PR head b7ea2faa78a0eaeddf7853ef6cba50ea5cde8d28, based on main e152ba8f6962ecab1d00a242d04b3407ebc5f59c (Windows 11 Pro, WinLibs MinGW GCC 15.2.0, CMake 4.4.4):

  • Built guest_formatting_tests and libc.prx successfully.
  • ctest --test-dir D:\anyps5_work\build-pr5070-review --output-on-failure -R '^guest_formatting$' --repeat until-fail:5 --timeout 30 passed 5/5.
  • tools/check_conventions.py --base origin/main --head HEAD and git diff --check origin/main...HEAD passed.

This was a focused target build only. I did not run the baseline regression or launch a title. No changes were made to the PR branch.

AI-assisted verification: OpenAI Codex. The PR author remains responsible for the submitted implementation.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6147345996 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5070#issuecomment-6147345996). Originally posted by [likecrank-dotcom](https://github.com/likecrank-dotcom) on 2026-10-13T14:03:27Z. --- Independent Windows verification of current PR head `b7ea2faa78a0eaeddf7853ef6cba50ea5cde8d28`, based on `main` `e152ba8f6962ecab1d00a242d04b3407ebc5f59c` (Windows 11 Pro, WinLibs MinGW GCC 15.2.0, CMake 4.4.4): - Built `guest_formatting_tests` and `libc.prx` successfully. - `ctest --test-dir D:\anyps5_work\build-pr5070-review --output-on-failure -R '^guest_formatting$' --repeat until-fail:5 --timeout 30` passed 5/5. - `tools/check_conventions.py --base origin/main --head HEAD` and `git diff --check origin/main...HEAD` passed. This was a focused target build only. I did not run the baseline regression or launch a title. No changes were made to the PR branch. AI-assisted verification: OpenAI Codex. The PR author remains responsible for the submitted implementation.
MarcZX10 commented 2026-10-13 19:24:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T19:24:19Z.


Thanks for the independent Windows run on predecessor head b7ea2faa. The current rebased PR head is b6c537b; it has the same Windows size-limit behavior and adds no code beyond the API/conflict adaptation and separated regression hunk, but the exact five-run Windows result is therefore supporting evidence from the prior head, not a current-head validation. I reran MinGW GCC 12 syntax-only checks for the implementation and test source on this head; a full Windows toolchain build is unavailable on my Linux host. If you can rerun guest_formatting on b6c537b, that would close the remaining validation gap. I also rebased this branch on current main; it now depends on #4981 for merge ordering and will need a final rebase if #4981 merges first.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6153398371 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5070#issuecomment-6153398371). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T19:24:19Z. --- Thanks for the independent Windows run on predecessor head `b7ea2faa`. The current rebased PR head is `b6c537b`; it has the same Windows size-limit behavior and adds no code beyond the API/conflict adaptation and separated regression hunk, but the exact five-run Windows result is therefore supporting evidence from the prior head, not a current-head validation. I reran MinGW GCC 12 syntax-only checks for the implementation and test source on this head; a full Windows toolchain build is unavailable on my Linux host. If you can rerun `guest_formatting` on `b6c537b`, that would close the remaining validation gap. I also rebased this branch on current main; it now depends on #4981 for merge ordering and will need a final rebase if #4981 merges first.
likecrank-dotcom commented 2026-10-13 19:29:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by likecrank-dotcom on 2026-10-13T19:29:07Z.


Follow-up Windows validation by OpenAI Codex (AI-assisted; report authored by an AI), in response to MarcZX100's request:

  • Fetched and verified current PR head b6c537b336dd8eb3b293c117337f1d3674f60b15 (not the earlier b7ea2faa head).
  • Rebuilt guest_formatting_tests on Windows 11 Pro (WinLibs GCC 15.2.0, Ninja, CMake/CTest 4.4.4).
  • guest_formatting passed five consecutive runs (5/5; 1.17 seconds total).
  • tools/check_conventions.py and git diff --check passed.

No PR code changes were made. The requested current-head Windows validation gap is now covered.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6153483711 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5070#issuecomment-6153483711). Originally posted by [likecrank-dotcom](https://github.com/likecrank-dotcom) on 2026-10-13T19:29:07Z. --- Follow-up Windows validation by OpenAI Codex (AI-assisted; report authored by an AI), in response to MarcZX100's request: - Fetched and verified current PR head `b6c537b336dd8eb3b293c117337f1d3674f60b15` (not the earlier `b7ea2faa` head). - Rebuilt `guest_formatting_tests` on Windows 11 Pro (WinLibs GCC 15.2.0, Ninja, CMake/CTest 4.4.4). - `guest_formatting` passed five consecutive runs (5/5; 1.17 seconds total). - `tools/check_conventions.py` and `git diff --check` passed. No PR code changes were made. The requested current-head Windows validation gap is now covered.
xXPBSXx commented 2026-10-14 01:07:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-14T01:07:13Z.


Windows 10 (19045), MinGW-w64 GCC 15.2.0, Release, -j4: head b6c537b33 of this PR merged onto main d7bb2fee3 (clean merge, 3 files).

  • guest_formatting passes (0.15 s, ctest).
  • With core/libs/prx/libc/src/Formatting.cpp taken back to main and the PR's new test lines kept, guest_formatting fails (unhandled exception St13runtime_error, what(): Formatting check failed, exit code 0xc0000409).
  • Not run: Linux, a console, a title.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6158579848 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5070#issuecomment-6158579848). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-14T01:07:13Z. --- Windows 10 (19045), MinGW-w64 GCC 15.2.0, Release, `-j4`: head `b6c537b33` of this PR merged onto `main` `d7bb2fee3` (clean merge, 3 files). - `guest_formatting` passes (0.15 s, ctest). - With `core/libs/prx/libc/src/Formatting.cpp` taken back to `main` and the PR's new test lines kept, `guest_formatting` fails (`unhandled exception St13runtime_error`, `what(): Formatting check failed`, exit code `0xc0000409`). - Not run: Linux, a console, a title. AI-assisted (Claude Code).
github-actions[bot] commented 2026-10-14 05:20:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T05:20:04Z.


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
#5662 docs/dev/debt/libc.md L57-58
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6161502723 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5070#issuecomment-6161502723). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-14T05:20:04Z. --- <!-- 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 | |---|---|---|---| | #5662 | `docs/dev/debt/libc.md` [L57-58](https://github.com/boykopovar/AnyPS5/blob/d8888df9b280a23077ff47d412bd7668c8c8b656/docs/dev/debt/libc.md#L57-L58) | | |
blawesom commented 2026-10-14 05:21:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-14T05:21:32Z.


Rebase handoff — rebased onto current main (all three commits, applies cleanly now), authorship unchanged.

Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON, AMD RX 9070 XT / RADV):

  • builds; tools/check_conventions.py --base origin/main passes
  • full suite: 1100/1101 — the only failure is the known main regression (agc_driver_tessellation segfault, #4727)

To pick it up:

git fetch https://github.com/blawesom/AnyPS5 rebase/5070
git checkout <your branch>
git merge --ff-only FETCH_HEAD

Head is c16404a5c.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6161520415 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5070#issuecomment-6161520415). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-14T05:21:32Z. --- **Rebase handoff** — rebased onto current `main` (all three commits, applies cleanly now), authorship unchanged. Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, `BUILD_TESTING=ON`, AMD RX 9070 XT / RADV): - builds; `tools/check_conventions.py --base origin/main` passes - **full suite: 1100/1101** — the only failure is the known `main` regression (`agc_driver_tessellation` segfault, #4727) **To pick it up:** ``` git fetch https://github.com/blawesom/AnyPS5 rebase/5070 git checkout <your branch> git merge --ff-only FETCH_HEAD ``` Head is `c16404a5c`.
oneandonlydean commented 2026-10-14 06:55:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T06:55:29Z.


Closing for now: this matches FreeBSD more closely, but no title on the list needs it yet, and with the queue this long we're only taking changes a named game needs. Reopen with the title ID and the log line it fails on, and it can go back in.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6162728462 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5070#issuecomment-6162728462). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T06:55:29Z. --- Closing for now: this matches FreeBSD more closely, but no title on the list needs it yet, and with the queue this long we're only taking changes a named game needs. Reopen with the title ID and the log line it fails on, and it can go back in.

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!5070
No description provided.