libc: snprintf and vsnprintf format into the buffer when the size exceeds INT_MAX, FreeBSD 11.4 fails with EOVERFLOW #8510
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 xXPBSXx on 2026-10-20T14:22:06Z.
Repro
snprintf(buf, (size_t)INT_MAX + 2, "x")andsnprintf(buf, SIZE_MAX, "x")(for example from a negativeintsize) return 1 and write "x".Expected (FreeBSD 11.4 lib/libc/stdio/vsnprintf.c:61-67): when
n - 1 > INT_MAX, set errno toEOVERFLOW(84), write a terminating NUL tobufand return -1.INT_MAX + 1is still accepted.Actual:
snprintf_nid_postfixandvsnprintf_nid_postfix(libcsrc/Formatting.cpp) pass the size on.Test:
core/libs/tests/Formatting.cpp(new cases;guest_formattingfails before the fix).Fix branch: https://github.com/xXPBSXx/AnyPS5/tree/fix/snprintf-size-overflow
Earlier attempts: #3982 and #5070 (closed).
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T19:27:28Z.
I found the ready branch
xXPBSXx/AnyPS5:fix/snprintf-size-overflowand reviewed its one commit. The boundary logic matches the report on inspection:size == INT_MAX + 1is accepted, larger sizes return before formatting, set guestEOVERFLOW(84), and NUL the buffer when present. There is no open PR for it, but the branch is 193 commits behind currentmain, so I am not opening a duplicate from that stale base. Please rebase/publish it if you still intend to submit it; I can review the current-head PR.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T19:29:25Z.
Correction to my previous comment: I missed that #8511 was closed after the maintainer reported a console run showing
snprintf/vsnprintfdo not reject sizes aboveINT_MAXwithEOVERFLOW. The branch matches FreeBSD 11.4, but that behavior is not the console behavior AnyPS5 should reproduce. I retract my earlier endorsement of carrying it forward as a fix; no PR should be opened from that branch for this issue unless new target evidence changes the conclusion.