libc: narrow snprintf on Windows crashes or misreports on a width or precision beyond int #11292

Closed
opened 2026-10-26 00:25:12 +00:00 by oneandonlydean · 0 comments
oneandonlydean commented 2026-10-26 00:25:12 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-26T00:25:12Z.


On Windows the narrow snprintf family goes through LibcDetail::FormatWindows, and a very large width or precision crashes or returns the wrong result, where Linux fails with -1 and errno 75. I haven't reproduced this; the results are from wachi35676's Windows 11 run (WinLibs GCC 15.2.0, Release) while testing #10813: https://github.com/boykopovar/AnyPS5/pull/10813#issuecomment-6405125956.

With snprintf_nid_postfix(buf, 16, fmt, 1):

  • %99999999999d and %.99999999999d end in 0xc00000fd (stack overflow)
  • %4294967296s ends in 0xc0000005
  • %.4294967296s returns 0
  • %2147483648d returns 1 with errno 0
  • %2147483647d and %2147483646d end in 0xc00000fd, where Linux returns 2147483647 and 2147483646

#10813 covers the same class for the wide family; this is the narrow counterpart. #3975 and #5293 are about unknown conversions aborting, which is a different failure. A fix needs bounded, instrumented tests rather than giant buffers.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:6031091173 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/11292). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-26T00:25:12Z. --- On Windows the narrow `snprintf` family goes through `LibcDetail::FormatWindows`, and a very large width or precision crashes or returns the wrong result, where Linux fails with -1 and errno 75. I haven't reproduced this; the results are from wachi35676's Windows 11 run (WinLibs GCC 15.2.0, Release) while testing #10813: https://github.com/boykopovar/AnyPS5/pull/10813#issuecomment-6405125956. With `snprintf_nid_postfix(buf, 16, fmt, 1)`: - `%99999999999d` and `%.99999999999d` end in 0xc00000fd (stack overflow) - `%4294967296s` ends in 0xc0000005 - `%.4294967296s` returns 0 - `%2147483648d` returns 1 with errno 0 - `%2147483647d` and `%2147483646d` end in 0xc00000fd, where Linux returns 2147483647 and 2147483646 #10813 covers the same class for the wide family; this is the narrow counterpart. #3975 and #5293 are about unknown conversions aborting, which is a different failure. A fix needs bounded, instrumented tests rather than giant buffers.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#11292
No description provided.