libc: snprintf and vsnprintf on Windows accept buffer sizes above INT_MAX+1 where FreeBSD returns -1 with EOVERFLOW; fix branch ready #3974
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 husseinkad on 2026-10-11T20:19:58Z.
On Windows,
snprintfandvsnprintfcalled with a buffer size too large for anintformat into the buffer and return the length. FreeBSD 11.4vsnprintf.cdoesif (n != 0) n--; if (n > INT_MAX)and then fails: it setserrno = EOVERFLOW(84), writes an empty string and returns -1. A guest that passesSIZE_MAXor another huge size as "no limit" gets a successful result here and an error on the console.Fix branch: https://github.com/husseinkad/AnyPS5/tree/fix/libc-vsnprintf-overflow (two commits on current main: the fix, then a boundary correction found in review;
libc/src/Formatting.cpp,tests/Formatting.cpp, oneTechnicalDebt.mdline). The check issize != 0 && size - 1 > INT_MAX, as in FreeBSD.Checks:
guest_formattingcases fail on main and pass with the change:INT_MAX + 1still formats (snprintf(buf, INT_MAX + 1, "ab")returns 2 and writesab),INT_MAX + 2up toSIZE_MAXgive -1, errno 84 and an empty string.INT_MAXbehave as before (size 0 leaves the buffer alone); a null buffer with an oversized size returns -1 without crashing; errno is untouched on success;sprintf,snprintf_sandvsnprintf_sare unchanged.vfprintf.c/vsnprintf.cshows the formatting output identical to main. Two independent reviews: the first one found an off-by-one atINT_MAX + 1in my first commit, fixed in the second commit and verified by a third review.check_conventions.pyis clean andpr_overlap.pyfinds no overlap.Caveats: Windows only; the Linux glibc path is not covered and was not built. The behaviour on a console is unverified (the reference is the FreeBSD source). Open PRs #3566, #3567 and #3569 also edit the Windows formatting code, in other functions.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T10:31:47Z.
I carried Hussein Kadhim’s two commits onto current main, preserving his author attribution, and opened draft PR #5070. The Linux formatting test passes, and MinGW GCC 12 syntax checks pass for the Windows source and tests. This host cannot run the repository’s supported Windows build because its MinGW toolchain uses SjLj exceptions; the Windows test report on the original branch is recorded in the PR. I moved the regression cases away from #4995’s test hunk. The draft is waiting on a merge-order response from #4981 because of a conflict in the shared libc debt file.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T06:53:45Z.
Closing: no title is known to reach this, and functions are only changed when a title needs them. If a title stops on or misbehaves because of it on current main, comment here with the title ID and the log line.