fix(libc): fail wide printf on a width or precision beyond int #10813
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10813"
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 MarcZX10 on 2026-10-25T02:40:42Z.
What
The wide printf family (
swprintf,vswprintf,snwprintf_sand the stream variants that shareFormatWide) accumulated the digits of a field width or precision in anintwith no bound, so a digit string aboveINT_MAXoverflowed a signed integer. A*width ofINT_MINalso overflowed when it was negated. A width or precision that does not fit anintnow fails the call like any other invalid format (empty buffer, -1), which is also what glibc'sswprintfreturns for it; widths up toINT_MAXparse as before. Two commits: fix, test.Open PRs #10766, #10379, #9953 and others touch
FormattingWide.cppfor unrelated behaviour; this change only touches the width and precision parsing.Tested
Rebase follow-up (2026-10-25): rebased onto current upstream
maine7e3e9c1984c293f06bff08428b8c89b7b932ac2without conflicts. On the rebased head, GCC 12.2 C++20-Wall -Wextra -Werrorsyntax checks passed forFormattingWide.cppandGuestWideFormatting.cpp;git diff --checkandtools/check_conventions.py --base upstream/mainpassed. The full local CMake test build could not configure because the SDL2 CMake package is unavailable, so no post-rebase runtime test is claimed. The runtime evidence below is from the prior base.Linux x86-64 (Debian 12, GCC 12), Ninja RelWithDebInfo,
-DANYPS5_ENABLE_ASAN=ONwith-fsanitize=undefined. The extendedguest_wide_formattingcase callsswprintfwith%99999999999d,%.99999999999d,%4294967296s,%.4294967296s,%2147483648ls,%.2147483648lsand a*width ofINT_MIN, and checks a negative*width still left-justifies. On currentmainUndefinedBehaviorSanitizer stops it withFormattingWide.cpp:130:72: runtime error: signed integer overflow: 999999999 * 10 cannot be represented in type 'int'; with the fix it passes. The console's result for these formats was not measured.python3 tools/check_conventions.py --base upstream/main --head HEADandgit diff --check upstream/main HEADpass. Windows, macOS and hardware were not run.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T06:03:22Z.
Review: COMMENTED
I noticed the additional Windows report on this PR:
swprintf_nid_postfixstill stack-overflows for%10000000d,%2147483647dand%.100000000dthrough thestd::snprintfpath inAppendNumber, even though those widths/precisions fit inint. That report is from a reviewer’s WinLibs GCC 15.2 run, not an independent reproduction on my side, and the failure also occurs onmain; I am not treating it as a regression introduced here. Since this change specifically hardens wide-format width/precision handling, could you assess whether rejecting or otherwise safely handling these very large but representable values belongs in this PR, or track it separately? A regression case at the largest in-range value would make the boundary clear.