Repository navigation
Conversation
…a PS5 Measured on libSceLibcInternal.sprx of a PS5 on firmware 13.60: - snprintf_s and vsnprintf_s: RSIZE_MAX is 2^61 - 1. A null buffer, size 0 or a size above RSIZE_MAX returns -1 with the buffer untouched; a null format returns -1 with buffer[0] zeroed; %n or a null %s, %ls or %S argument returns -23, keeps the output written before it and zeroes buffer[0]. Every violation calls the constraint handler with the console's message, a null pointer and EINVAL. - sscanf_s and vsscanf_s: the size argument is 64 bits. A %s or %[ field of at least size characters stores its first size characters without a terminator and is a matching failure; %c stores at most size characters and succeeds. Null destinations and sizes above RSIZE_MAX call the handler and return the assignments, or -23 before any conversion. A literal mismatch at the end of input returns the assignments, and %n counts as a conversion for the EOF result. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
Overlap coordination for a follow-up to #9321: I have a narrow wide-scanner patch for incomplete-exponent and literal-at-EOF behavior. Its code and tests are separate from this PR's measured formatting constraints, but both branches update the same libc debt bullet, which |
|
Thanks for checking. Making your follow-up depend on this PR and rebasing the debt bullet after it merges works for me. If this one is still waiting when yours is ready, go ahead first and I'll rebase the debt bullet here. |
|
@orezraey a merge-order note: #9479 (Windows |
|
Thanks for coordinating. #9479 going first works for me; once it merges I'll rebase this PR's test file over it, keeping both check functions and both calls in |
|
A data point for the The
What this means: sources disagree on whether the default handler ends the process. For a title that installs no handler, this bundled
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…les ship Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks, that is a useful distinction. In 49903de the |
|
I ran Setup: a homebrew payload process (ps5-payload-sdk v0.45, elfldr) on a PS5 with firmware 11.60 (
So the threshold the console uses is exactly 2^61 - 1, as this PR has it; on The probe sources and the raw output of both runs follow. The header comments had an internal probe number, which was removed; the code is unchanged, and the build IDs are the hashes of the original files. run 1: probe.c#include <errno.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <ps5/kernel.h> /* only for kernel_get_fw_version() */
#ifndef PROBE_NAME
#define PROBE_NAME "unnamed"
#endif
#ifndef PROBE_BUILD
#define PROBE_BUILD "unbuilt"
#endif
/* Self limit: on timeout the runner can only close the connection, not end the process on the console.
The probe ends itself after at most PROBE_MAX_S seconds (the build script sets timeout - 10 s). */
#ifndef PROBE_MAX_S
#define PROBE_MAX_S 50
#endif
static void probe_alarm(int sig) {
static const char msg[] = "TIMEOUT\tprobe self limit\n";
(void)sig;
(void)!write(1, msg, sizeof msg - 1);
_exit(124);
}
static int cases = 0;
static void probe_header(void) {
char utc[32];
time_t now = time(0);
struct tm tmv;
gmtime_r(&now, &tmv);
strftime(utc, sizeof utc, "%Y-%m-%dT%H:%M:%SZ", &tmv);
printf("PROBE\t%s\tfw=0x%08x\tbuild=%s\tpid=%d\tutc=%s\n", PROBE_NAME, kernel_get_fw_version(), PROBE_BUILD,
getpid(), utc);
fflush(stdout);
}
/* CASE: id, description of the call, return value as long, errno (0 if not set), extra (hex/bytes). */
static void probe_case(const char* id, const char* call, long ret, int err, const char* extra) {
printf("CASE\t%s\t%s\t%ld\t%d\t%s\n", id, call, ret, err, extra ? extra : "-");
fflush(stdout);
cases++;
}
static void probe_end(void) {
printf("END\t%d\n", cases);
fflush(stdout);
}
#include <dlfcn.h>
#include <setjmp.h>
#include <stdlib.h>
#include <pthread.h>
#include <sys/types.h>
static sigjmp_buf guard_env;
static volatile int guard_sig = 0;
static volatile int guard_active = 0;
static volatile int guard_hits = 0;
static void guard_handler(int s) {
static const char msg[] = "FAULT\tprobe guard: fault outside a guarded call or too many faults\n";
if(!guard_active || ++guard_hits > 8) {
(void)!write(1, msg, sizeof msg - 1);
_exit(125);
}
guard_sig = s;
guard_active = 0;
siglongjmp(guard_env, 1);
}
static void guard_arm(void) {
struct sigaction sa;
memset(&sa, 0, sizeof sa);
sa.sa_handler = guard_handler;
sigaction(SIGSEGV, &sa, 0);
sigaction(SIGBUS, &sa, 0);
sigaction(SIGABRT, &sa, 0);
}
#define CALL(rvar, evar, expr) do { errno = 0; guard_sig = 0; rvar = -1; if(sigsetjmp(guard_env, 1) == 0) { guard_active = 1; rvar = (expr); } guard_active = 0; evar = errno; } while(0)
/* Probe: vsnprintf_s of libSceLibcInternal.sprx (dlsym) on firmware 11.60 (libc.md:118 'snprintf_s and vsnprintf_s follow C11 K.3.5.3.5
and K.3.5.3.12 ... a null buffer or format, size of 0 or above RSIZE_MAX, any %n and a null %s return a negative value and set buffer[0]
to zero ... the constraint handler is not invoked, and the console's error value is unverified'). Prototype int vsnprintf_s(char*, size_t,
const char*, va_list); a wrapper builds the va_list. A constraint handler that only counts calls is set when set_constraint_handler_s
exists. The buffer is local, 16 bytes plus a 16 byte guard area filled with 0x7e. No %*d and no width. At most 40 calls, each guarded. */
#include <stdarg.h>
typedef int (*vs_fn)(char*, size_t, const char*, va_list);
typedef void (*handler_t)(const char*, void*, int);
typedef handler_t (*sch_fn)(handler_t);
static vs_fn vs;
static volatile int handler_calls = 0;
static void counting_handler(const char* msg, void* ptr, int err) { (void)msg; (void)ptr; (void)err; handler_calls++; }
static int wrap(char* buf, size_t n, const char* fmt, ...) {
va_list ap;
va_start(ap, fmt);
int r = vs(buf, n, fmt, ap);
va_end(ap);
return r;
}
static char area[32];
static void cell(const char* id, const char* what, int use_null_buf, size_t n, const char* fmt, long arg) {
memset(area, 0x7e, sizeof area);
int r, e;
handler_calls = 0;
CALL(r, e, wrap(use_null_buf ? 0 : area, n, fmt, arg));
char ex[160];
snprintf(ex, sizeof ex, "rc=%d b0=0x%02x b1=0x%02x b2=0x%02x b3=0x%02x b15=0x%02x b16=0x%02x handler_calls=%d signal=%d", r, (unsigned char)area[0],
(unsigned char)area[1], (unsigned char)area[2], (unsigned char)area[3], (unsigned char)area[15], (unsigned char)area[16], (int)handler_calls,
(int)guard_sig);
probe_case(id, what, guard_sig ? -1 : r, e, ex);
}
int main(void) {
signal(SIGALRM, probe_alarm);
alarm(PROBE_MAX_S);
probe_header();
guard_arm();
void* h = dlopen("libSceLibcInternal.sprx", RTLD_LAZY);
vs = (vs_fn)(h ? dlsym(h, "vsnprintf_s") : 0);
sch_fn sch = (sch_fn)(h ? dlsym(h, "set_constraint_handler_s") : 0);
char ex[8];
snprintf(ex, sizeof ex, "%d%d%d", !!h, !!vs, !!sch);
probe_case("0", "dlopen libSceLibcInternal.sprx, dlsym vsnprintf_s set_constraint_handler_s (1 yes, 0 no)", 0, 0, ex);
if(!vs) { probe_end(); return 0; }
if(sch) sch(counting_handler);
cell("a.1", "vsnprintf_s(buf, 16, \"%d\", 42)", 0, 16, "%d", 42);
cell("a.2", "vsnprintf_s(buf, 3, \"%d\", 42) exact fit", 0, 3, "%d", 42);
cell("a.3", "vsnprintf_s(buf, 2, \"%d\", 42) truncation", 0, 2, "%d", 42);
cell("a.4", "vsnprintf_s(buf, 1, \"%d\", 42) truncation", 0, 1, "%d", 42);
cell("a.5", "vsnprintf_s(buf, 16, \"\")", 0, 16, "", 0);
cell("b.1", "vsnprintf_s(buf, 0, \"%d\", 42)", 0, 0, "%d", 42);
cell("b.2", "vsnprintf_s(buf, 0x7fffffffffffffff, \"%d\", 42)", 0, 0x7fffffffffffffffULL, "%d", 42);
cell("b.3", "vsnprintf_s(buf, 0x8000000000000000, \"%d\", 42)", 0, 0x8000000000000000ULL, "%d", 42);
cell("b.4", "vsnprintf_s(buf, SIZE_MAX, \"%d\", 42)", 0, (size_t)-1, "%d", 42);
cell("c.1", "vsnprintf_s(buf, 16, \"%n\")", 0, 16, "%n", (long)(intptr_t)&area[24]);
cell("c.2", "vsnprintf_s(buf, 16, \"a%nb\")", 0, 16, "a%nb", (long)(intptr_t)&area[24]);
cell("c.3", "vsnprintf_s(buf, 16, \"%s\", NULL)", 0, 16, "%s", 0);
cell("c.4", "vsnprintf_s(buf, 16, \"x%sy\", \"ab\")", 0, 16, "x%sy", (long)(intptr_t)"ab");
cell("d.1", "vsnprintf_s(NULL, 16, \"%d\", 42)", 1, 16, "%d", 42);
cell("d.2", "vsnprintf_s(NULL, 0, \"%d\", 42)", 1, 0, "%d", 42);
memset(area, 0x7e, sizeof area);
int r, e;
handler_calls = 0;
CALL(r, e, wrap(area, 16, (const char*)0, 0L));
snprintf(ex, 1, "%s", "");
char ex2[120];
snprintf(ex2, sizeof ex2, "rc=%d b0=0x%02x b1=0x%02x handler_calls=%d signal=%d", r, (unsigned char)area[0], (unsigned char)area[1], (int)handler_calls, (int)guard_sig);
probe_case("e", "vsnprintf_s(buf, 16, NULL format)", guard_sig ? -1 : r, e, ex2);
probe_end();
return 0;
}run 1: raw outputrun 2: probe.c#include <errno.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <ps5/kernel.h> /* only for kernel_get_fw_version() */
#ifndef PROBE_NAME
#define PROBE_NAME "unnamed"
#endif
#ifndef PROBE_BUILD
#define PROBE_BUILD "unbuilt"
#endif
/* Self limit: on timeout the runner can only close the connection, not end the process on the console.
The probe ends itself after at most PROBE_MAX_S seconds (the build script sets timeout - 10 s). */
#ifndef PROBE_MAX_S
#define PROBE_MAX_S 50
#endif
static void probe_alarm(int sig) {
static const char msg[] = "TIMEOUT\tprobe self limit\n";
(void)sig;
(void)!write(1, msg, sizeof msg - 1);
_exit(124);
}
static int cases = 0;
static void probe_header(void) {
char utc[32];
time_t now = time(0);
struct tm tmv;
gmtime_r(&now, &tmv);
strftime(utc, sizeof utc, "%Y-%m-%dT%H:%M:%SZ", &tmv);
printf("PROBE\t%s\tfw=0x%08x\tbuild=%s\tpid=%d\tutc=%s\n", PROBE_NAME, kernel_get_fw_version(), PROBE_BUILD,
getpid(), utc);
fflush(stdout);
}
/* CASE: id, description of the call, return value as long, errno (0 if not set), extra (hex/bytes). */
static void probe_case(const char* id, const char* call, long ret, int err, const char* extra) {
printf("CASE\t%s\t%s\t%ld\t%d\t%s\n", id, call, ret, err, extra ? extra : "-");
fflush(stdout);
cases++;
}
static void probe_end(void) {
printf("END\t%d\n", cases);
fflush(stdout);
}
#include <dlfcn.h>
#include <setjmp.h>
#include <stdlib.h>
#include <pthread.h>
#include <sys/types.h>
static sigjmp_buf guard_env;
static volatile int guard_sig = 0;
static volatile int guard_active = 0;
static volatile int guard_hits = 0;
static void guard_handler(int s) {
static const char msg[] = "FAULT\tprobe guard: fault outside a guarded call or too many faults\n";
if(!guard_active || ++guard_hits > 8) {
(void)!write(1, msg, sizeof msg - 1);
_exit(125);
}
guard_sig = s;
guard_active = 0;
siglongjmp(guard_env, 1);
}
static void guard_arm(void) {
struct sigaction sa;
memset(&sa, 0, sizeof sa);
sa.sa_handler = guard_handler;
sigaction(SIGSEGV, &sa, 0);
sigaction(SIGBUS, &sa, 0);
sigaction(SIGABRT, &sa, 0);
}
#define CALL(rvar, evar, expr) do { errno = 0; guard_sig = 0; rvar = -1; if(sigsetjmp(guard_env, 1) == 0) { guard_active = 1; rvar = (expr); } guard_active = 0; evar = errno; } while(0)
/* Probe: size threshold of vsnprintf_s of libSceLibcInternal.sprx (dlsym) on firmware 11.60 (libc.md:118 'size ... above RSIZE_MAX';
follow-up of an earlier run in which size 0x7fffffffffffffff returned -1 and called the constraint handler, where AnyPS5 formats).
Prototype int vsnprintf_s(char*, size_t, const char*, va_list). The output "42" is 2 bytes long, so no size writes beyond a 32 byte local
buffer. Group a: sizes 2^k for k = 4..63 (rc and handler calls; 60 calls); b: bisection between the last accepted and the first rejected
power of two (at most 64 steps, assumes the accepted sizes form a prefix, which group a shows); c: the sizes next to the threshold. */
#include <stdarg.h>
typedef int (*vs_fn)(char*, size_t, const char*, va_list);
typedef void (*handler_t)(const char*, void*, int);
typedef handler_t (*sch_fn)(handler_t);
static vs_fn vs;
static volatile int handler_calls = 0;
static void counting_handler(const char* msg, void* ptr, int err) { (void)msg; (void)ptr; (void)err; handler_calls++; }
static int wrap(char* buf, size_t n, const char* fmt, ...) {
va_list ap;
va_start(ap, fmt);
int r = vs(buf, n, fmt, ap);
va_end(ap);
return r;
}
static char area[32];
static int try_size(size_t n, int* handler_out) {
memset(area, 0x7e, sizeof area);
int r, e;
handler_calls = 0;
CALL(r, e, wrap(area, n, "%d", 42));
(void)e;
if(handler_out) *handler_out = handler_calls;
return guard_sig ? -1000 : r;
}
int main(void) {
signal(SIGALRM, probe_alarm);
alarm(PROBE_MAX_S);
probe_header();
guard_arm();
void* h = dlopen("libSceLibcInternal.sprx", RTLD_LAZY);
vs = (vs_fn)(h ? dlsym(h, "vsnprintf_s") : 0);
sch_fn sch = (sch_fn)(h ? dlsym(h, "set_constraint_handler_s") : 0);
char ex[100];
snprintf(ex, sizeof ex, "%d%d%d", !!h, !!vs, !!sch);
probe_case("0", "dlopen libSceLibcInternal.sprx, dlsym vsnprintf_s set_constraint_handler_s (1 yes, 0 no)", 0, 0, ex);
if(!vs) { probe_end(); return 0; }
if(sch) sch(counting_handler);
size_t last_ok = 0, first_bad = 0;
int hc;
for(int k = 4; k <= 63; k++) {
size_t n = (size_t)1 << k;
int r = try_size(n, &hc);
char id[16], w[48];
snprintf(id, sizeof id, "a.%d", k);
snprintf(w, sizeof w, "vsnprintf_s(buf, 1<<%d, \"%%d\", 42)", k);
snprintf(ex, sizeof ex, "size=0x%llx rc=%d handler_calls=%d b0=0x%02x b1=0x%02x b2=0x%02x", (unsigned long long)n, r, hc, (unsigned char)area[0], (unsigned char)area[1], (unsigned char)area[2]);
probe_case(id, w, r, 0, ex);
if(r >= 0) last_ok = n;
else if(!first_bad) first_bad = n;
}
snprintf(ex, sizeof ex, "last_ok=0x%llx first_bad=0x%llx", (unsigned long long)last_ok, (unsigned long long)first_bad);
probe_case("a.s", "largest accepted and first rejected power of two", 0, 0, ex);
if(last_ok && first_bad && first_bad > last_ok) {
size_t lo = last_ok, hi = first_bad;
int steps = 0;
while(hi - lo > 1 && steps < 64) {
size_t mid = lo + (hi - lo) / 2;
if(try_size(mid, 0) >= 0) lo = mid; else hi = mid;
steps++;
}
snprintf(ex, sizeof ex, "largest_accepted=0x%llx smallest_rejected=0x%llx steps=%d", (unsigned long long)lo, (unsigned long long)hi, steps);
probe_case("b", "bisection between last accepted and first rejected size", 0, 0, ex);
static const long long off[] = {-2, -1, 0, 1, 2};
for(int i = 0; i < 5; i++) {
size_t n = lo + (size_t)off[i];
int r = try_size(n, &hc);
char id[8], w[48];
snprintf(id, sizeof id, "c.%d", i);
snprintf(w, sizeof w, "vsnprintf_s(buf, largest_accepted%+lld)", off[i]);
snprintf(ex, sizeof ex, "size=0x%llx rc=%d handler_calls=%d", (unsigned long long)n, r, hc);
probe_case(id, w, r, 0, ex);
}
}
probe_end();
return 0;
}run 2: raw outputAI-assisted (Claude Code). |
|
Second console measurement, on a newer firmware: it agrees with the tables above. PS5, firmware 13.590.001. A payload called the system
Not in the tables: |
|
Another data point, from a title's own module: the
One detail the table does not cover: with a null format and a size of exactly 2^61 - 1, the module reports In the same run, AI-assisted (Claude Code). |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
Nothing blocks this draft review; one optional consistency point is noted below.
What I ran
Reviewed head 16498b1a6a3393138771095c3d0c487f75098e2c using repo_read.py. No commands or tests were run; this review interface is read-only.
Read all seven changed files listed in manifest.json: WindowsFormatting.hpp, Formatting.cpp, Formatting.cpp tests, GuestScanCount.cpp, GuestStdioVariadic.cpp, GuestStrings.cpp, and libc.md. All were marked included. No exclusions were listed in the manifest; files.json was not available through the reader.
Results
| Check | Result | Note |
|---|---|---|
| Changed code review | passed | Seven changed files read |
| Tests | not run | Read-only review interface |
| Console behavior | not run | Stream forms unmeasured on-console |
Findings
Blocking
None.
Non-blocking
- The secure stream wide
%lcbranch keeps the full parsed width and returns early when it exceeds the destination capacity (Formatting.cpp:431); unlike the narrow stream%cbranch, it does not apply the low-32-bit width rule and clamp to capacity. The added wide-field tests coversscanf_s, not the stream variant. Since the description explicitly says stream forms were not run on-console, consider adding a reference-based stream case or recording this as unverified if parity is intended.
Not verified
- No build or tests were run.
- PS5 console behavior was not run during this review. The description reports console measurements for formatting and string scanning, and contributor-run reference-module observations for stream scanning; those are author-reported evidence.
files.jsoncould not be read through the provided reader.
To get this to a good state
Nothing is required. Optional: add a stream %lc width/capacity case or clarify the intended distinction from the narrow stream %c behavior.
What
snprintf_s,vsnprintf_s,sscanf_sandvsscanf_sfollowed C11 Annex K with guessed constants. Their debt entries said the constraint handler is not invoked and the console's values are unverified. In a payload process on a PS5 (firmware 13.60,libSceLibcInternal.sprx) most of those guesses differ.snprintf_s / vsnprintf_s (both behave the same;
errnonever changes):mainbefore this PRRSIZE_MAX0x1fffffffffffffffpasses,0x2000000000000000fails)SIZE_MAX >> 1size0 or aboveRSIZE_MAX"snprintf_s: bad argument"(orvsnprintf_s: …), a null pointer and 22SIZE_MAX >> 1acceptedbuffer[0]= 0, handler"…: bad format argument"buffer[0]= 0, no handler%n/%hn(also after truncation)buffer[0]= 0; handler"printf_s: %n disallowed"; the pointer is not written%sargument (also%.0s)"printf_s: bad %s argument"%ls/%Sargument"printf_s: bad %ls argument"sscanf_s / vsscanf_s (both behave the same):
mainbefore this PRunsigned int%s/%[field ofsizeor more characterssizecharacters stored without a terminator; matching failure, returns the items assigned so farbuffer[0]= 0%cwith a width abovesizesizecharacters and succeeds, consuming only thosebuffer[0]= 0%ls/%l[and%lcwith a width abovesize(titles' ownlibc.prx, measured by JJenkx)%lsand%l[follow the narrow rules;%lcstoressizeunits and succeeds, but consumes the whole width%lcconsumed only the stored charactersRSIZE_MAX"scanf_s: bad %c, %s, or %[ size"%s/%c/%[destination"scanf_s: bad %c, %s, or %[ argument", checked before reading input (also on empty input)EOF, no handler%por floating-point destinationEOFand"x"gives 0, without the handlerEOF%nincluded) has completedEOFEOF, handler"sscanf_s: bad argument"/"vsscanf_s: bad argument"EOF, no handler""with"x%d")EOFfscanf_s / vfscanf_s / scanf_s: a literal mismatch at the end of input now returns the assignments, as
sscanf_sdoes: empty input with"x%2c%n"returns 0 and leaveserrno, the%ntarget and the destination untouched, following JJenkx's CPU-only run of two referencelibcmodules (earlier heads andmainreturnEOF).%%at the end of input still returnsEOF. A%cfield takes the same width rule and size clamp as insscanf_s:%8c%nonabcwith size 2 storesab, sets the count to 2 and leavescnext; with size 4 it storesabc; onabcdefwith size 4 it storesabcdand leavesenext (JJenkx's reference rows;mainreturned 0 before reading). The stream forms were not run on a console.The -23 is the same with a recording handler, an empty one and
ignore_handler_s.set_constraint_handler_s,abort_handler_sandignore_handler_sare exported, and passing NULL reinstalls the default.The formatter's terminator: to leave the partial output unterminated on a violation,
FormatOutputnow writes the terminator once at the end instead of after every piece. Every caller goes throughFormatWindows, which does that at the end. On success every output is the same as before, which the existing formatting tests check.Not measured, recorded in
docs/dev/debt/libc.md:"<message>\n"before ending the process; AnyPS5's default now writes the message and returns, as thelibc.prxtitles ship does (fix(libc): write the constraint message and return from the default handler #9935's change, which reachedmainwith fix(libc): bound and report the Annex K copies as measured on a PS5 #10270).%yis copied to the output by the console and still throws here.%hsargument was not measured.swscanf_s's size width (it still readsunsigned int) was not measured.Tests:
guest_formatting,guest_scan_count(also JJenkx's wide rows) andguest_stringscheck the measured cases, with the old expectations updated and size arguments passed assize_t.guest_scan_countfails if the -23 constant is changed.How the console was measured
libSceLibcInternal.sprxwas loaded withdlopen, and every function was taken from it withdlsym.~and integer destinations preset to -7.libcfmt3andlibcfmt4reinstall the default handler and end their own process with it, to see what it does.Console output (excerpt, copied unchanged)
Tested
1c3b118df8:main(0263899e99, with fix(libc): retain ordinary short character scan fields #13119) was merged in.Formatting.cppmet in two places: the%nbookkeeping keeps both fix(libc): retain ordinary short character scan fields #13119's ordinary rule and this PR's secure contiguous one, andsscanfuses fix(libc): retain ordinary short character scan fields #13119'sScansInProcesswith this PR's null secure name. As agreed with JJenkx, the shared stream%cloop now takes a%cwidth by its low 32 bits (zero or aboveINT_MAXreads one) and clamps a secure field to its size instead of failing before reading;guest_stdio_variadicgains five stream rows from JJenkx's matrix (%8c%nonabcwith sizes 2 and 4, onabcdefwith size 4,%2147483648cand%4294967298c), which fail when the clamp is removed.tests/Formatting.cppkeeps this PR's unterminated%scheck and fix(libc): retain ordinary short character scan fields #13119'sCheckOrdinaryCharacterScans;libc.mdkeeps this PR's entries, and fix(libc): retain ordinary short character scan fields #13119's sentence about the secure%cwidth and size is dropped since both paths now follow those references. At this headguest_formatting,guest_scan_count,guest_stdio_variadic,file_streamsandguest_stringspass three runs in a row on Windows (WinLibs GCC 15.2) and on Linux (WSL, GCC);check_conventionsreports no errors (onedebt-lengthwarning on alibc.mdentry this PR did not add).d44f653788:main(b8efa6292a, with fix(libc): print unknown printf conversions and ' as titles' libc.prx does #11907) was merged in. Onlycore/libs/tests/Formatting.cppmet, inCheckSecureFormat: it keeps this PR's measuredsnprintf_s/vsnprintf_schecks and addsmain's new cases,[%y][%-4k]printed literally (with no constraint call) and%hhnrefused with the buffer emptied and the destination untouched. At this headguest_formatting,guest_wide_formatting,guest_scan_count,guest_stdio_variadicandguest_stringspass three runs in a row on Windows (WinLibs GCC 15.2) and on Linux (WSL, GCC 16.2), andcheck_conventionsreports 0 errors.0f9bb22b03:main(c2eafe4461, with fix(libc): retain short wide scanf character fields #9863 and fix(libc): bound and report the Annex K copies as measured on a PS5 #10270) was merged in. Onlylibc.mdmet: it keepsmain'swcsncat_sandset_constraint_handler_sentries (the default handler now writes the message and returns), fix(libc): retain short wide scanf character fields #9863's short-field wording in the_WStoul/swscanf_sentry with this PR's measuredsscanf_scomparison, and this PR'ssnwprintf_ssentence.Formatting.cppnow usesSonyRsizeMaxfromSonyCrt.hpp(same 2^61 - 1) instead of its ownsecureSizeMax, as agreed with harisibrar1 on this PR. At this headguest_formatting,guest_scan_count,guest_stdio_variadic,guest_stringsandguest_safe_errorspass three runs in a row on Windows (MinGW, GCC 15.2) and on Linux (WSL, GCC 16.2);check_conventionsreports no errors (onedebt-lengthwarning on the long_WStoulentry).d826fd16d3:mainwas merged in, with fix(libc): match bundled narrow scansets and scan directive parsing #12428; the unknown-conversion exit now comes before the secure block.guest_formatting,guest_wide_formatting,guest_scan_count,guest_stdio_variadic,guest_safe_errorsandguest_stringspass three runs in a row on Windows (MinGW, GCC 15.2) and on Linux (WSL, GCC);check_conventionspasses. Disregard the Linux result recorded for24f4242cbd: another checkout changed the shared tree while that build ran. This Linux run replaces it, on a tree nothing else touched.24f4242cbd:main(1d91f2966d, with fix(libc): read wide scanf fields byte by byte, as titles' libc.prx does #12468) was merged in and the secure bounds were re-applied on itssourcescanner: forsscanf_sandvsscanf_s,%ls,%lcand%l[keep the firstsizecharacters without a terminator when they do not fit, and%lcconsumes the rest of its width, which now counts bytes as fix(libc): read wide scanf fields byte by byte, as titles' libc.prx does #12468's loop does. Stream forms keepmain's behaviour.libc.mdkeeps fix(libc): read wide scanf fields byte by byte, as titles' libc.prx does #12468'sscanf_swording and this PR's. At this headguest_formatting,guest_scan_count,guest_wide_formatting,guest_stdio_variadic,guest_strings,guest_wide_stringsandguest_safe_errorspass three runs in a row on Windows (WinLibs GCC 15.2) and on Linux (WSL2, GCC);check_conventionsreports no errors.e16c92d39fmergesmain(93dbd0f82a, with feat(libc): add Dinkumware float bit helpers from firmware #8397); only thesscanf_sdebt line met feat(libc): add Dinkumware float bit helpers from firmware #8397's new_LDnormentry, and both are kept. At this head the twelve tests below pass three runs in a row on Windows (WinLibs GCC 15.2) and on Linux (WSL, GCC 16.2), andcheck_conventionsreports no errors (onedebt-lengthwarning on alibc.mdentry this PR did not add).053ebd8a33:main(1ff6c8739b) was merged in. Onlylibc.mdmet, at thescanf_sandfreopen_sentries: it keeps this PR'sscanf_swording with JJenkx's end-of-input result andmain's newfreopen_sentry with its constraint handler calls. At this headguest_formatting,guest_scan_count,guest_wide_formatting,guest_stdio_variadic,guest_stringsandguest_safe_errorspass three runs in a row on Windows (WinLibs GCC 15.2) and on Linux (WSL2, GCC);check_conventionspasses (the onedebt-lengthwarning on the_WStoulentry, as before).29d8de386f:main(3b32cc7b61, with fix(libc): read swscanf scanset ranges and string lengths as titles do #12420) was merged in. Onlylibc.mdmet, in the_WStoul/swscanf_sentry: it keeps fix(libc): read swscanf scanset ranges and string lengths as titles do #12420's scanset range, length and%pwording and this PR's measuredsscanf_scomparison (64-bit size, firstsizecharacters stored without a terminator). At this headguest_formatting,guest_scan_count,guest_wide_formatting,guest_stdio_variadic,guest_stringsandguest_safe_errorspass three runs in a row on Windows (WinLibs GCC 15.2) and on Linux (WSL2, GCC);check_conventionspasses (the onedebt-lengthwarning on the_WStoulentry, as before).d00ac4ec91:main(0362b1521c, with feat(libc): implement dprintf and vdprintf #12933) was merged in. Onlylibc.mdmet: it keeps feat(libc): implement dprintf and vdprintf #12933's newdprintf/vdprintfentry and this PR's measuredsnprintf_s/vsnprintf_sentry, with the oldvsscanf_sentry still removed. At this headguest_formatting,guest_scan_count,guest_wide_formatting,guest_stdio_variadic,guest_stringsandguest_safe_errorspass three runs in a row on Windows (WinLibs GCC 15.2) and on Linux (WSL2, GCC);check_conventionspasses (the onedebt-lengthwarning on the_WStoulentry, as before).4eaf64fee1:sscanf_s/vsscanf_stake a%cwidth by its low 32 bits and read one character when it is zero or aboveINT_MAX, following JJenkx's reference rows (%2147483648conabcstores one byte with size 2 or 4;%4294967298creads two).guest_scan_countgains those three rows, which fail on16a242bbaa. The stream scanner keepsmain's path until fix(libc): retain short stream character scan fields #13057 and fix(libc): retain ordinary short character scan fields #13119 land. At this headguest_formatting,guest_scan_count,guest_wide_formatting,guest_stdio_variadic,guest_stringsandguest_safe_errorspass three runs in a row on Windows (WinLibs GCC 15.2) and on Linux (WSL2, GCC);check_conventionspasses (the onedebt-lengthwarning on the_WStoulentry, as before).16a242bbaa: the stream scanner (fscanf_s,vfscanf_s,scanf_s) returns the assignments for a literal mismatch at the end of input, following JJenkx's reference rows.guest_stdio_variadicgains the empty-input"x%2c%n"case (0,errno97,%n-77 and the 0xa5 destination untouched) and%%at the end of file (EOF); the first check fails on the previous head. The twelve tests listed below pass three runs in a row on Windows (WinLibs GCC) and on Linux (WSL Ubuntu, GCC);check_conventionspasses (the existing_WStouldebt-lengthwarning only).3b0fa2fc4d:main(157b02c4f1, with fix(libc): end sscanf and vsscanf at a q length on Linux and macOS #11852) was merged in. OnlyFormatting.cppmet, insscanf: it keeps fix(libc): end sscanf and vsscanf at a q length on Linux and macOS #11852's cut at aqlength directive (applied tosscanfandvsscanfonly, as onmain) and this PR'sScanGuestsignature with a null secure name. At this headguest_formatting,guest_scan_count,guest_stdio_variadic,guest_stringsandguest_safe_errorspass three runs in a row on Windows (WinLibs GCC 15.2) and on Linux (WSL2, GCC);check_conventionspasses (the onedebt-lengthwarning on the_WStoulentry, as before).ec862a495a:%lcwith a width abovesizeconsumes the whole width, following JJenkx's run of titles'libc.prx(PPSA07923, PPSA05916).guest_scan_countgainsCheckWideFieldswith the eight rows of that table, and its two%lcrows fail onacb1ec494f. At this headguest_formatting,guest_scan_count,guest_stdio_variadic,guest_stringsandguest_safe_errorspass three runs in a row on Windows (WinLibs GCC 15.2) and on Linux (WSL2, GCC);check_conventionspasses (the onedebt-lengthwarning on the_WStoulentry, as before).acb1ec494f:main(f80ce6cec1, with docs(libc): record feholdexcept, fegetexcept, setlocale and strcasecmp as measured on a PS5 #11121) was merged in. Onlylibc.mdmet: it keeps this PR'ssnprintf_s/vsnprintf_sandset_constraint_handler_swording and its removal of the oldvsscanf_sentry, and main'slocaleconventry with its removal of thesetlocaleentry. At this headguest_formatting,guest_scan_count,guest_stdio_variadic,guest_stringsandguest_safe_errorspass three runs in a row on Windows (WinLibs GCC 15.2) and on Linux (WSL2, GCC);check_conventionspasses (the onedebt-lengthwarning on the_WStoulentry, as before).0055557985:main(5bdda3661e, with docs(libc): record that libSceLibcInternal does not export memmem or memccpy #10176 and fix(libc): leave errno alone for out-of-range float and double in swscanf #9973) was merged in. Onlylibc.mdmet: it keeps this PR's measuredsscanf_s/vsscanf_sand_WStoul/swscanf_sentries,main's firmware 13.60 export note onmemmem and memccpyand fix(libc): leave errno alone for out-of-range float and double in swscanf #9973's newfloating scan errnoentry. At this head the twelve tests below pass three runs in a row on Windows (WinLibs GCC 15.2) and on Linux (WSL2, GCC);check_conventionspasses (the onedebt-lengthwarning on the_WStoulentry, as before).2f05aac2d2:main(5b85225ef3, with feat(libc): add the Annex K stream printf, scanf and freopen_s functions #9527'sScanSource) was merged in5652af2d1a. This PR's measuredsscanf_s/vsscanf_srules were ported ontoScanSourceforStringSourceonly;StreamSourcekeepsmain'sfscanf_s/scanf_spath.2f05aac2d2makes feat(libc): add the Annex K stream printf, scanf and freopen_s functions #9527'sGuestStdioVariadicchecks expect the measuredsnprintf_s(-23 with a handler call) and undersizedsscanf_s%sresults instead of the old ones. At this head the twelve tests below pass three runs in a row on Windows and on Linux, and the 49 libc tests matchingscan|format|print|string|stdio|safe|constraint|bounds|crt|locale|widepass on Windows. Before that, head after mergingmainagain (9dbc017c71, with fix(libc): convert scanf integers as FreeBSD does on Windows #9479):efeb582327; onlycore/libs/tests/Formatting.cppmet, keeping this PR's constraint-handler helpers and measuredsscanf_stoo-small%scheck together with fix(libc): convert scanf integers as FreeBSD does on Windows #9479'sCheckIntegerScanWidthsand itsRunCheckscall. At this head the twelve tests below pass three runs in a row on Windows and on Linux (the Linuxpublic_headersaudit times out at 30 s on the WSL/mnt/ccheckout, unrelated to this change). Before that,main(ac65cf490e, with docs(debt): cite the bundled libc.prx for _Mtx_trylock, strdup and strndup #9613) was merged inb824e3b277; only thestrndupandsnprintf_sdebt lines met, keeping docs(debt): cite the bundled libc.prx for _Mtx_trylock, strdup and strndup #9613'sstrndupdisassembly reading and this PR's measuredsnprintf_sentry (the oldvsscanf_sline stays removed, as its measuredsscanf_sentry replaces it). At this head the twelve tests below pass three runs in a row on Windows and on Linux. Before that,main(66e6772ca2, with docs(libc): correct the RSIZE_MAX that swprintf_s and vswprintf_s assume #9360) was merged in6b9e2f1574; only thesnwprintf_sandswprintf_sdebt lines met, keeping this PR'ssnwprintf_swording andmain'sswprintf_slimit. Before that,main(f26434afa3, with refactor(libs): add full export headers for libs #10706) was merged in7b400cbcfe. The tests take their declarations fromlibc/include/Api.hpp.guest_formatting,guest_scan_count,guest_wide_formatting,guest_wide_stream_scan,guest_stdio_variadic,guest_locale,guest_strings,guest_wide_strings,guest_wide_conversion,guest_safe_errors,guest_crtandguest_bounds_checkingpass three runs in a row on Windows (WinLibs GCC) and on Linux (WSL Ubuntu, GCC), which now also builds the#ifndef _WIN32wide scan path.public_headersaudit andcheck_conventionspass (onedebt-lengthwarning on the_WStoulentry, already 3083 characters onmain).Windows 11, WinLibs GCC 15.2.0, Release: the 30 libc tests whose names cover formatting, scanning, strings, wide characters, streams, locales and bounds checking pass. Linux not built: the
#ifndef _WIN32wide scan path inScanGuestwas changed with the narrow rules and only passed ag++syntax check, so this PR relies on the Linux CI job to build and run it.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)mainwith fix(libc): bound and report the Annex K copies as measured on a PS5 #10270; feat(libc): implement std::_Atomic_assert #7851 (hypermoist) addslibc.mdentries next to the ones this PR edits (merge order only); fix(libc): check asctime_s and ctime_s arguments as titles' libc.prx does #12574 (JJenkx) editslibc.mdlines this PR changes (merge order only); fix(libc): check swprintf_s and snwprintf_s as titles' libc.prx does #12627 (JJenkx) rewrites thesnwprintf_sandswprintf_sentries this PR edits inlibc.md(merge order only); fix(libc): check qsort_s arguments as titles' libc.prx does #12598 (JJenkx) rewrites theqsort_sentry next to thelibc.mdentries this PR edits (merge order only); fix(libc): sort like the console's qsort and qsort_s #9688, fix(libc): retain short wide scanf character fields #9863, fix(libc): reject an invalid _WStoul base like Dinkumware instead of … #10729, feat(libc): implement lfind and lsearch #11621, fix(libc): print unknown printf conversions and ' as titles' libc.prx does #11907, fix(libc): print %C, %S and a zero %lc in the printf families as titles' libc.prx does #12397, fix(libc): read wide scanf fields byte by byte, as titles' libc.prx does #12468, fix(libc): fail a 0x with no hex digit and keep errno for in-range floats in sscanf_s #12530, fix(libc): store a scanned NaN as the default quiet NaN in sscanf_s #12532 and fix(libc): retain ordinary short character scan fields #13119 have merged