fix(libc): set EOVERFLOW when vswprintf truncates or the size exceeds INT_MAX #4833

Closed
Gashrod1 wants to merge 1 commit from upstream-pr/4833 into main
Gashrod1 commented 2026-10-12 23:09:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Gashrod1 on 2026-10-12T23:09:02Z.


What

vswprintf_nid_postfix (and swprintf, which goes through it) returned -1 on truncation without setting errno, and accepted sizes above INT_MAX + 1. FreeBSD sets EOVERFLOW in both cases (lib/libc/stdio/vswprintf.c, same in stable/11): if (n - 1 > INT_MAX) { errno = EOVERFLOW; *s = L'\0'; return (-1); } before formatting, and if (nwc == n) { s[n - 1] = L'\0'; errno = EOVERFLOW; return (-1); } when the output does not fit.

Both now set errno 84. The truncated text and its terminator were already the same as FreeBSD's and are unchanged; a size above INT_MAX + 1 now writes only the terminator and returns -1 before formatting.

guest_wide_formatting checks errno for a truncated result, for a result whose terminator does not fit and for a size of INT_MAX + 2. It fails on main and passes with the change.

Tested

Linux (Arch, GCC), Release, BUILD_TESTING=ON, based on main 43e3a70f8: guest_wide_formatting aborts on main and passes with the change (3 runs); full build and full ctest pass. Windows (WinLibs MinGW-w64 GCC 15.2.0 r7, NVIDIA RTX 5060), Release, BUILD_TESTING=ON: full build and full ctest pass (1019 tests, the same 7 skipped as on main). No title or homebrew run.

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 (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4836057485 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4833). Originally posted by [Gashrod1](https://github.com/Gashrod1) on 2026-10-12T23:09:02Z. --- ### What `vswprintf_nid_postfix` (and `swprintf`, which goes through it) returned -1 on truncation without setting errno, and accepted sizes above `INT_MAX + 1`. FreeBSD sets EOVERFLOW in both cases ([`lib/libc/stdio/vswprintf.c`](https://github.com/freebsd/freebsd-src/blob/main/lib/libc/stdio/vswprintf.c), same in stable/11): `if (n - 1 > INT_MAX) { errno = EOVERFLOW; *s = L'\0'; return (-1); }` before formatting, and `if (nwc == n) { s[n - 1] = L'\0'; errno = EOVERFLOW; return (-1); }` when the output does not fit. Both now set errno 84. The truncated text and its terminator were already the same as FreeBSD's and are unchanged; a size above `INT_MAX + 1` now writes only the terminator and returns -1 before formatting. `guest_wide_formatting` checks errno for a truncated result, for a result whose terminator does not fit and for a size of `INT_MAX + 2`. It fails on `main` and passes with the change. ### Tested Linux (Arch, GCC), Release, `BUILD_TESTING=ON`, based on `main` `43e3a70f8`: `guest_wide_formatting` aborts on `main` and passes with the change (3 runs); full build and full `ctest` pass. Windows (WinLibs MinGW-w64 GCC 15.2.0 r7, NVIDIA RTX 5060), Release, `BUILD_TESTING=ON`: full build and full `ctest` pass (1019 tests, the same 7 skipped as on `main`). No title or homebrew run. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
oneandonlydean commented 2026-10-14 02:37:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:37:01Z.


Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6159635528 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4833#issuecomment-6159635528). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T02:37:01Z. --- Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

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