feat(libc): implement vsnprintf_s and vsscanf_s #1981
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1981"
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 overlordxrz-source on 2026-10-09T03:41:42Z.
What
Cyberpunk 2077 (PPSA04029) imports two
libcfunctions that are still throwing stubs onmain,libcCyberUnknown18andlibcCyberUnknown19.tools/nid_names.pyresolves their NIDs:rWSuTWY2JN0vsnprintf_stfNbpqL3D0Mvsscanf_sBoth NIDs are in the PPSA04029 import list attached to #266.
rWSuTWY2JN0is also in the PPSA03396 list in #269.The stub comments described a file-size idiom called as
(handle, 0, 2)and(handle, 0, 0). That contradicts the hash-verified names, as the comment onstrnlen_sdid beforeb9c1c884. #492 left these two stubs alone because of it. This PR removes the stubs and their comments.These are the C11 Annex K signatures, not MSVC's:
int vsnprintf_s(char*, rsize_t, const char*, va_list)int vsscanf_s(const char*, const char*, va_list)MSVC's
vsnprintf_shas an extracountargument. The guestlibcexports the Annex K-onlyset_constraint_handler_s,abort_handler_sandignore_handler_s, plussnwprintf_s,vsnwprintf_sandwcsnlen_s. It exports none of MSVC's underscore forms such as_vsnprintf_s(see the export list on psdevwiki's LibSceLibcInternal page). The existingsnprintf_s,vsprintf_s,snwprintf_sandsscanf_sexports here already use the C11 shapes. #1498 implementsrWSuTWY2JN0with MSVC'scountargument, so a C11 caller's format pointer would be read ascountthere.vsnprintf_srejects these with a negative result: a null buffer or format, a size of 0 or aboveRSIZE_MAX, any%n(%%nis still literal text), and a null%s,%lsor%Sargument. When the buffer is usable it writes an empty string. To find null strings it walks a copy of the guestva_list(*widths and precisions, integers, doubles,long double, pointers) and stops at the first conversion it doesn't know, leaving that to the formatter. Otherwise it formats through the existingvsnprintfexport, which uses the Windows guest formatter on Windows. It returns the full length and truncates with a terminating null.vsscanf_sreturnsEOFfor a null input, format or target pointer. Otherwise it runs the scannersscanf_salready uses, with sized%s,%cand%[. The size is read asunsigned int, assscanf_sdoes._sexports here do.Log
I don't own Cyberpunk 2077, so I can't paste a line where PPSA04029 stops on
main. I found no stop line for these NIDs in any issue or PR. The evidence is the import lists in #266 and #269. If someone with either title can post theNotImplementedline forrWSuTWY2JN0ortfNbpqL3D0Mfrommain, I'll add it here.Tested
aarch64 Debian 13 host. The full project can't be built here because it needs x86-64.
core/libs/tests/GuestSecureFormatting.cpp(guest_secure_formatting), linked natively againstFormatting.cppthrough the non-Windowsva_listpath, passes and also passes with UBSan. Thevsnprintf_schecks cover formatting, truncation with the full count, literal%%n,%nwith and without flags, null%sand%ls(including after*,%f,%Lf,%c,%pand%lldarguments), null format and buffer, size 0 and a size aboveRSIZE_MAXleaving the buffer alone. Thevsscanf_schecks cover sized%s,%cand%[, a too-small buffer, empty input, and null input, format and targets.Formatting.cpp,Export.cppand the test compile with-Wall -Wextra(Zig 0.17, clang 22). The only warnings are the existing ones fromGeneral.hppandFileStream.hpp. Zig's clang 22 lacks__builtin_sysv_va_list, soFormatting.cpponmaindoesn't compile for x86_64-windows-gnu here either. With those builtins mapped to the plainva_listones, the only errors on that target are the existingva_startlines; the new Windows path (LibcDetail::FormatArguments) compiles. It hasn't been run on Windows.python3 tools/check_conventions.py --base origin/mainpasses.Checklist
main. The one other open PR that changes these functions is #1498, which also changes these stubs as part of a larger change; see WhatNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T03:42:07Z.
Progress report (
f145139→9a4e12e)📈 System libraries: 84.83% (+0.07%, +2 implemented, -2 removed functions)
✅ 2 implemented
vsnprintf_s_nid_postfixvsscanf_s_nid_postfix🗑️ 2 removed
libcCyberUnknown18libcCyberUnknown19Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T04:14:00Z.
Review: CHANGES_REQUESTED
The tests exercise the behavior this patch implements, and the updated build/conventions checks pass. The stated need is still only the PPSA import lists; the PR explicitly says no current-main
NotImplementedcall was found and no title was run. CONTRIBUTING.md says an import list alone does not show that a title reaches an export and asks for a reproduced failure or a concrete project need with its evidence limits. Since this adds two nontrivial secure-formatting implementations with assumed console behavior, please provide runtime evidence or a demonstrated project need before review.Imported from boykopovar/AnyPS5. Originally posted by overlordxrz-source on 2026-10-09T04:54:58Z.
Thanks. I don't have a current-main runtime line. The only call-site evidence is main's own note from #358's static GOT-xref pass on PPSA04029 (
// Live Cyberpunk 2077 import used in an fopen/fseek/ftell-like file-size idiom as (handle, 0, 2)aboverWSuTWY2JN0, and(handle, 0, 0)abovetfNbpqL3D0M). That shows a call site exists, not that boot reaches it. That observed argument shape also doesn't match the hash-verifiedvsnprintf_s/vsscanf_ssignatures, which is why #492 left these stubs alone. Either the static attribution or the name is wrong, and I can't settle that without the binary. I'm moving this to draft until someone with PPSA04029 (or PPSA03396) posts the current-mainrWSuTWY2JN0 not implemented/tfNbpqL3D0M not implementedline or a disassembly of the call site that fixes the signature.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T09:30:43Z.
Closing: only the import lists in #266 and #269 show these, and the call shape noted in
Export.cppdoesn't match the names yet. Reopen with thenot implementedline from main, or the disassembled call site, when a title stops here.Pull request closed