fix(libc): check swprintf_s and snwprintf_s as titles' libc.prx does #12627
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12627"
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 JJenkx on 2026-10-28T23:30:52Z.
What
swprintf_s,vswprintf_s,snwprintf_sandvsnwprintf_snow check their arguments and output the way thelibc.prxthat titles ship does. Onmainthey called no constraint handler, returned -1 for everything, and accepted sizes up to2^62elements. Measured natively on PPSA07923 and PPSA05916, which agree:snwprintf_s,vsnwprintf_sswprintf_s,vswprintf_ssize - 1units and clears the first;"<name>: buffer overflow"withERANGESIZE_MAX >> 3elements"<name>: bad argument"buffer[0] = 0,"<name>: bad format argument"%n, null%s, null%lsbuffer[0]cleared after the text before it;"wprintf_s: %n disallowed","wprintf_s: bad %s argument"or"wprintf_s: bad %ls argument""<name>: buffer overflow"when that text already filled the bufferEvery report uses
EINVAL(except the overflow) and a null pointer.<name>is the function's own name; thevforms use theirs too. The element limit is2^61 - 1, the same number as the narrow byte limit, not divided bysizeof(char16_t).Implementation: one
FormatWideSecurehelper replaces the four bodies.FormatWidenow writes into a caller's string, so the text produced before a violation is kept, as the titles keep it in the buffer. In secure mode it throws the titles' messages.%S: the titles print%Sliterally, as an unknown conversion, in all four functions. That's #12397's change, not this PR's, and the%Srows are left out of the comparison below. Merged locally with #12397, #11907 and #11893, the four functions match the titles on every row including%S, andguest_wide_formattingpasses. #12397 conflicts with this PR only on theswprintf_s and vswprintf_sdebt entry; the resolution keeps this PR's measured rule plus #12397's%Swording.Not stacked on #9087: this PR doesn't touch
Formatting.cpp, so it's based onmain. It conflicts with #9087 only on thesnwprintf_sdebt entry, which both edit. The resolution is this PR's entry: with the measured limit the narrow and wide sides agree again, so #9087's sentence about them disagreeing no longer applies. orezraey asked for the wide pair as a separate PR.Fulfilled dependency: #9935 reached main through merged #10270. The default handler writes its message and returns; integrating #9935’s exact closed head into pinned main leaves main’s tree unchanged.
Tested
Current-main integration — 2026-11-09 UTC. Head
3abfc9a3015e5a4a5e786707a23a45f4c3df4357preserves public head6d6c12de5195c06f94a58e6227bec1b630702aa7and integrates pinned main7259cce11195f360698772da8c0b3af756bf7c8f. Conflict resolution retains both the topic and main's newer source/test/debt changes; maintainer commits and attribution remain intact.Linux x86-64, GCC 16.2.1, Ninja Release: actual libc/libkernel and focused fixture owners rebuilt. 15/15 CPU executions pass, zero skips (5 groups × three repetitions):
guest_wide_formatting,guest_wide_stream_scan,guest_formatting,guest_stdio_variadic,guest_crt.public_headers, conventions and whitespace checks pass. The matching plain-main control passed 102 selected CPU executions and its header audit. CPU fixtures execute unpatched production libraries; this is not a full SDK or patched-title runtime qualification.No new Windows/macOS, console, GPU, title or performance result is claimed. Source checks preserve the existing production topic; historical reports below retain their original pins.
Build/test logs, exact heads, source/ancestry checks and provider pins, SHA-256
52727be6594b9c15bf9a5535fef374b985e9526aabe5f3ef5cf5857dfeeb1a0d. The public archive and all 178 manifest files were download/hash verified.Current-main integration — 2026-11-04. Head
6d6c12de5195c06f94a58e6227bec1b630702aa7includes mainb11c7bf84f5d2f636ff60166cc3371bd071e24d5and preserves previous public commits and attribution/licence notices. Keeps the measured wide secure-format constraints and the concise%Slimitation. Main’s default constraint handler now writes and returns through the fulfilled #10270/#9935 change.Linux x86-64, GCC 16.2.1, Ninja Release, BUILD_TESTING=ON: rebuilt actual libc/Ampr and selected executables.
guest_wide_formatting,guest_formatting,guest_stdio_variadic,guest_wide_conversion,guest_scan_count,guest_wide_stream_scaneach pass 3/3 (18 runtime passes, zero skips);public_headers, conventions and whitespace checks pass. Pinned main passes all 17 selected baseline groups 3/3 (51 passes) plus headers. Before/after dependency checks agree: 34 recursive trees and 31,551 tracked blobs, zero errors; the update=none QuickJS test262 corpus is explicitly excluded from these library inputs.Source/parent/gitlink proofs, library/test hashes, raw logs/JUnit and head-leased push receipts: qualification archive, SHA-256
7c347f620951ad6f39068740750949212c6412815da094a46a96eca1d15c8bbf(download verified). Older platform, stress, negative-control and reference reports retain their original pins; no new Windows/macOS, full-suite, SDK-module, console, title/GPU or performance claim. AI-assisted: yes (Codex).Earlier dated qualifications below retain their original source/platform pins.
Latest Linux qualification (2026-11-02): exact head
e1becbe8feb67df3e585fb8f662e21eb773d3633on pinned maina4eca2a056bf3bbbec98ab42e9d28163e4ea9cb8. Keeps main’s bool AppendUtf16/WideEncodingError handling and the measured secure null-string constraint report. The previously restored f8fe5ccc wide%S debt remains; #12397 is not integrated. The obsolete pre-9953 byte-copy encoding claim is narrowed to the still-unverified secure encoding behavior.4 focused groups repeated three times: 12 passes, zero skips. Public headers, conventions, whitespace, raw libc/test builds and the actual production NID-patching command passed. MinGW syntax passed for Formatting.cpp, FormattingWide.cpp. No new Windows/macOS runtime, bundled-SDK reference, native title, GPU or performance claim; earlier evidence retains its historical pins.
Earlier pinned qualifications follow.
Windows 11, WinLibs GCC 15.2.0 UCRT r7, Release,
main319621ba2e.vforms are called through a hand-built System Vva_list; the same loader reproduces #9087'svsnprintf_sresults exactly, which checks that construction. Each case compares the return value, the handler's calls, error, pointer and message, and the buffer contents.swprintf_sandsnwprintf_s, 18 cases each: fits, fits exactly, too long, size 1, size 0, null buffer, null format,2^60,2^60 + 1,2^61 - 1,2^61,SIZE_MAX,%n, null%s, null%ls, an empty format, and%npast the end.maindiffers in 22 of 36; this PR: 0.vswprintf_sandvsnwprintf_s, 10 cases each: 0 of 20 differ.%Srows are left out, as described above.guest_wide_formattinginstalls a recording handler.CheckSecureWideConstraintschecks every row of the table for all four functions.CheckSecureWideBoundarynow uses the measured2^61 - 1limit instead of(SIZE_MAX >> 1) / 2.main'sFormattingWide.cppthe test fails.guest_wide_formatting,guest_safe_errors,guest_formatting,guest_wide_strings,guest_wide_stream_scanandguest_wide_conversionpass 3/3. Conventions pass.Merge order: the existing agreement with orezraey is retained for the remaining open #9087: this PR lands first, then #9087 integrates main while keeping these wide-format debt entries. #10270 has already merged and is fulfilled history.
Current qualification — 2026-10-30
Integrated upstream main
08a10d225306ad102b57408e2ef7566bcfb829b2atc713fbf818cfb2ca97bf771ab290140b0ebaadb1, retaining the actual previous head and main as parents. Manual conflict resolution changes only debt documentation; production and test files equal the automatic merge output. Both parents' added test lines and main gitlinks are preserved.Linux CPU: 9 passes (guest_wide_formatting, guest_formatting, guest_crt); public_headers 1 passes; no skips. MinGW source syntax and conventions pass.
No new Windows/macOS runtime, native SDK, game, GPU or performance claim. The Windows user pause remains in force.
Evidence: immutable source and qualification receipts, SHA-256
61f5500e7526ea4e107159927de78c37db7e0ac1cb7ebd8625b22ab0ad5d9bd7(download verified).Independent Windows validation, reported by bunbeans2-arch for topic
c713fbf818cfb2ca97bf771ab290140b0ebaadb1against mainf7f03daf52: Windows 11 Pro 22631, i9-9900K, MSYS2 UCRT64 GCC 16.1, Release.guest_wide_formattingpasses 5/5; retaining the new test with mainFormattingWide.cppfails 5/5 at the accepted-boundary clearing assertion; plain main passes 3/3. This is the contributor's run, not a new local Windows execution.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)Current-main refresh (2026-11-12). Public head
600a910b82e1da60ca48b2bc185e0395d5a868c1integrates main59f3a64cf61fbe4a63699a4d61ae734b4375df03, preserving the prior public commits and maintainer edits. The only conflict was two adjacent test calls: both this PR'sCheckSecureWideConstraints()and main'sCheckMeasuredWideConversions()are retained. All 266 changed production/test lines are identical to the prior topic relative to its base; main's newer conversions stay intact.Actual libc and these six test executables rebuilt separately on main and the refreshed branch:
guest_wide_formatting,guest_formatting,guest_stdio_variadic,guest_wide_conversion,guest_scan_count,guest_wide_stream_scan. Each group passed three times per arm: 18/18 main, 18/18 change, zero skips. Source identity/cleanliness checks, conventions, whitespace and the final latest-main merge preview pass. The ordinary main fixtures ran on main; this is maintenance qualification, not a fresh bundled-library semantic measurement or a new negative control.Exact pins, commands, both build logs, full test output/JUnit and preservation proof — SHA-256
7ce20289120304e979bab15ba92c3d3c80196b47f89a4d5b07bd8a43b26ffa16; downloaded and all 20 archive members verified. Prior Windows/reference/other-platform evidence retains its original pins. No fresh Windows, GPU/native title, full SDK or performance claim.