Repository navigation
Conversation
|
Windows run (Windows 11 26300, WinLibs GCC 15.2.0 r7, Release, full build):
|
Dextroid17
left a comment
There was a problem hiding this comment.
Verified against the reference: the boundary is FreeBSD's, exactly. The honest coverage picture is that nothing on this PR builds or runs it — and one sentence of the debt entry is not true for the wide-format route.
Head d5f16993, merged onto my checkout's upstream/main at 752db7da — 145 commits ahead of this PR's own GitHub base 0a8b1d32; Formatting.cpp is unchanged between the two, the test file and TechnicalDebt.md moved and both merged cleanly. The API reports MERGEABLE/CLEAN. This is the fix for #3974, whose own caveat — "Windows only; the Linux glibc path is not covered and was not built" — is the right frame for everything below.
The rule is right, checked against the source rather than the issue
FreeBSD 11.4 lib/libc/stdio/vsnprintf.c, vsnprintf_l:
on = n;
if (n != 0)
n--;
if (n > INT_MAX) {
errno = EOVERFLOW;
*str = '\0';
return (EOF);
}It decrements before comparing, so the overflow point is size > INT_MAX + 1 — which is what size - 1 <= INT_MAX expresses — and the actions line up (*str = '\0', errno = EOVERFLOW, return -1 = EOF). I ran both predicates against each other over 0..199, INT_MAX-3 … INT_MAX+5, and the extremes (2^31, 2^31+1/2/3, 2^32-1, 2^63, 2^64-1): no mismatch on any input, INT_MAX + 1 allowed and INT_MAX + 2 refused, which is the pair your second commit's headline names. The size == 0 disjunct comes first so size - 1 never underflows — and it is load-bearing, since without it SIZE_MAX <= INT_MAX is false and size == 0 would read as an overflow.
The errno is the guest's, and 84 is this tree's established form for it
__error_nid_postfix() returns &errno (core/libs/prx/libc/src/Process.cpp:158-160), so the bare errno here is the guest's slot, and the repo already maps the host's EOVERFLOW onto the guest's 84 (core/libs/prx/libc/src/FileAndHeap.cpp:215 and :226, core/libs/prx/libkernel/File/src/Open.cpp:129-130) and names that value directly (libkernel/KernelErrors.hpp:91, libkernel/Pthread/Posix/Sem.cpp:21). A host macro would give the guest something other than 84 (75 on Linux, and the MS CRT's own value differs again), so the literal is the deliberate and correct form here.
One deliberate divergence worth a clause. FreeBSD writes *str = '\0' in that branch unconditionally; your helper guards the buffer first, so a guest passing (nullptr, INT_MAX + 2) gets -1 where the reference writes through a null pointer. That is a hardening rather than a port, and "as FreeBSD 11.4 does" reads as byte-for-byte — one clause ("ours also accepts a null buffer, where the reference writes through it") removes the puzzle.
Finding — the entry's Linux sentence is not true for the wide-format route
The new debt entry says "On Linux the limit is whatever the host glibc applies". That holds only for the narrow path: snprintf_nid_postfix (core/libs/prx/libc/src/Formatting.cpp:311-317) and vsnprintf_nid_postfix (:407-419) send any format carrying a wide conversion to LibcDetail::FormatWindows, where glibc is not involved and there is no size check — FormatOutput validates the output length, not size (WindowsFormatting.hpp:161-165, ctor at :64). So a guest calling snprintf(buf, INT_MAX + 2, "%ls") on Linux is neither refused with EOVERFLOW — which the console, being FreeBSD-derived, does for that format too — nor handled by glibc. Suggested clause: "…whatever the host glibc applies for the narrow formats; a wide conversion goes to the guest formatter instead, so glibc's limit does not apply to it".
Coverage, as it actually is — and this is the part I would put in the description
Nothing on this PR builds or runs guest_formatting: gh pr checks 3982 reports linux and windows as skipping, both gated to push/workflow_dispatch with full set only for manual dispatch (build.yml:193, :240), and the one PR-time job, relinker, configures -DANYPS5_RELINKER_ONLY=ON, where CMakeLists.txt:71-73 returns before core/libs/prx/libc — the target does not exist in that build at all. What has run the boundary is @LeandroLP23's manual Windows build reported below (3/3 on this base, and guest_formatting aborts with Formatting.cpp reverted), plus the predicate comparison above. My local run — ctest --test-dir build -R '^guest_formatting$' → 1/1 Passed, and nm -C build/tests/guest_formatting_tests | grep -c ExceedsIntMax → 0 — is a non-regression result only, because the new checks sit inside #ifdef _WIN32 (core/libs/tests/Formatting.cpp:136-158).
Also checked, and it holds up
- Every call site is covered:
snprintfdirectly (Formatting.cpp:277, asserted at test:150,:155,:157) andvsnprintfthroughFormatList(test :153), whoseSIZE_MAXprobe exercises the second entry point. sprintf/vsprintfhave no size argument to guard, and the entry documentssnprintf_s/vsnprintf_sas unlimited — so the scope statement is honest rather than an omission.- Author preserved: the commit is Hussein Kadhim's, carried by this PR (
gh pr view 3982 --json commits). - Context for a reviewer reading the thread: the combined-run failure @LeandroLP23 reports together with #3987 comes from #3987's test still expecting the old
%1$d/%'dbehaviour, not from this change.
Not verified, so it is not claimed: the console's own libc.prx — as #3974 says, the code is assumed shared with FreeBSD and unchecked on a title — and Windows execution by me; the Windows evidence in this thread is @LeandroLP23's manual build, not mine.
Hermes Agent 🤖 at your service
|
Conflicts with main in |
d5f1699 to
ad24886
Compare
ad24886 to
fea57fa
Compare
fea57fa to
e0ca58e
Compare
|
Thanks for the source-level review and boundary comparison. I agree the debt wording should distinguish the narrow Linux path from the wide-conversion path, and the description should call out the deliberate null-buffer hardening difference from FreeBSD. The Windows run reported above confirms the focused boundary test catches the regression on the PR code; the Linux run remains a non-regression check only. I will update the wording to make those limits explicit. |
|
Thanks — the rebase reads clean from here too. Head One thing that carries across the force-push: For the record the two wording edits are two different edits, and the second is @oneandonlydean's from the rebase comment:
Nothing else is outstanding from my side; the null-buffer hardening clause in the description is the only other wording point. Hermes Agent 🤖 at your service |
FreeBSD's vsnprintf sets EOVERFLOW, writes an empty string and returns -1 when the size exceeds INT_MAX. The Windows implementation formatted into the buffer and returned the length instead. (cherry picked from commit 646312b)
FreeBSD's vsnprintf subtracts the terminator before comparing with INT_MAX, so only sizes above INT_MAX + 1 fail with EOVERFLOW. (cherry picked from commit 0f9fc58)
e0ca58e to
e3bf942
Compare
|
I updated the debt entry to scope the Linux glibc limit to narrow formats and note the guest formatter path for wide conversions ( |
|
Both updates read as described, and I would keep the implementation where it is — here is the measurement behind that call. Read at Enabling the guard on Linux is new Linux behaviour, not extra coverage — with the threshold stated precisely. So a Linux guest gets a normal formatted write-back at each of those sizes today, and with the guard on, One consequence for the wording. "Narrow formats retain the host glibc limit" reads as though glibc enforces something on Everything else from the review stands: the predicate comparison against FreeBSD 11.4's decrement-then-compare, the call-site coverage, and the coverage caveat — the |
|
What shows that the console's |
|
You're right that nothing I measured shows the console's You say the console's printf family is Dinkumware's I'm leaving the implementation as it is until there is evidence either way. |
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
|
|
Closing, since the premise doesn't hold on the console. @oneandonlydean asked what shows that the console's
So a size above Welcome to reopen with a console result or a title that passes such a size. |
What
snprintf/vsnprintfoverflow behavior: sizes aboveINT_MAX + 1clear the output, setEOVERFLOW, and return-1.INT_MAX,INT_MAX + 1,INT_MAX + 2,SIZE_MAX, null buffers, and preserved errno behavior.*str = '\0'unconditionally. This is deliberate hardening for that error path, not a general claim that null buffers are accepted.Tested
guest_formatting_tests; CTestguest_formattingpassed (1/1). This does not exercise the Windows-only branch.tools/check_conventions.py --base upstream/mainandgit diff --checkpassed.Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repository