libc: the Windows printf family aborts on %qd, %D, %O, %U, unknown conversions and a trailing % that FreeBSD formats; fix branch ready #3975

Closed
opened 2026-10-11 20:20:18 +00:00 by husseinkad · 1 comment
husseinkad commented 2026-10-11 20:20:18 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by husseinkad on 2026-10-11T20:20:18Z.


On Windows, the guest printf family (FormatWindows) throws and aborts the guest on four things FreeBSD 11.4 vfprintf.c formats:

  • the q length modifier (%qd, %qu, %qx)
  • the %D, %O and %U conversions (synonyms for %ld, %lo, %lu)
  • an unknown conversion character, which FreeBSD prints as itself with the width and - flag (%y, %5%, %-5y)
  • a format ending in a lone %, where FreeBSD stops (snprintf("100%") returns 3)

Fix branch: https://github.com/husseinkad/AnyPS5/tree/fix/libc-format-freebsd-conversions (two commits on current main: the change, then a correction found in review; libc/include/WindowsFormatting.hpp, tests/Formatting.cpp, one TechnicalDebt.md entry). The unknown-conversion branch skips every character that FreeBSD's vfprintf handles itself (taken from the 11.4 case labels), so %m, %1$d, %'d, %l5d, %lqd and %qc keep throwing as before instead of printing wrong output.

Checks:

  • The new guest_formatting cases fail on main (abort) and pass with the change, including a loop that expects the unsupported forms above to still throw; guest_wide_formatting, file_streams and guest_standard_stream pass.
  • 500k random format strings through the old and the new header: none of the ~26k that formatted before changed in output or return value, and about 15k that used to throw now format. A differential fuzz of 1.2M cases against the FreeBSD 11.4 sources (compiled into a harness) found no new mismatch; the branch fixes about 180k cases that differed on main.
  • Three independent reviews. The first found that my first commit silently misformatted %m, %1$d, %'d and modifiers in odd order; the second commit fixes that and the last review was clean. check_conventions.py is clean and pr_overlap.py finds no overlap; #3566, #3567 and #3569 also edit this file in other places, so a textual rebase may be needed.

Not fixed here, the same on main: %05%, %05y, %05s and %05c pad with blanks where FreeBSD pads with zeros (listed in TechnicalDebt.md); % u prints a leading space; %.1lc applies the precision; %jp, %qs, %hhs, doubled lengths such as %lh and %qq are rejected; %m and positional %1$d are unsupported (the last is #3569). Only Windows was built and run; the Linux glibc path still prints %D, %O, %U and unknown conversions as written. The reference is the FreeBSD source, not a console.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5804820231 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3975). Originally posted by [husseinkad](https://github.com/husseinkad) on 2026-10-11T20:20:18Z. --- On Windows, the guest `printf` family (`FormatWindows`) throws and aborts the guest on four things FreeBSD 11.4 `vfprintf.c` formats: - the `q` length modifier (`%qd`, `%qu`, `%qx`) - the `%D`, `%O` and `%U` conversions (synonyms for `%ld`, `%lo`, `%lu`) - an unknown conversion character, which FreeBSD prints as itself with the width and `-` flag (`%y`, `%5%`, `%-5y`) - a format ending in a lone `%`, where FreeBSD stops (`snprintf("100%")` returns 3) Fix branch: https://github.com/husseinkad/AnyPS5/tree/fix/libc-format-freebsd-conversions (two commits on current main: the change, then a correction found in review; `libc/include/WindowsFormatting.hpp`, `tests/Formatting.cpp`, one `TechnicalDebt.md` entry). The unknown-conversion branch skips every character that FreeBSD's `vfprintf` handles itself (taken from the 11.4 `case` labels), so `%m`, `%1$d`, `%'d`, `%l5d`, `%lqd` and `%qc` keep throwing as before instead of printing wrong output. Checks: - The new `guest_formatting` cases fail on main (abort) and pass with the change, including a loop that expects the unsupported forms above to still throw; `guest_wide_formatting`, `file_streams` and `guest_standard_stream` pass. - 500k random format strings through the old and the new header: none of the ~26k that formatted before changed in output or return value, and about 15k that used to throw now format. A differential fuzz of 1.2M cases against the FreeBSD 11.4 sources (compiled into a harness) found no new mismatch; the branch fixes about 180k cases that differed on main. - Three independent reviews. The first found that my first commit silently misformatted `%m`, `%1$d`, `%'d` and modifiers in odd order; the second commit fixes that and the last review was clean. `check_conventions.py` is clean and `pr_overlap.py` finds no overlap; #3566, #3567 and #3569 also edit this file in other places, so a textual rebase may be needed. Not fixed here, the same on main: `%05%`, `%05y`, `%05s` and `%05c` pad with blanks where FreeBSD pads with zeros (listed in `TechnicalDebt.md`); `% u` prints a leading space; `%.1lc` applies the precision; `%jp`, `%qs`, `%hhs`, doubled lengths such as `%lh` and `%qq` are rejected; `%m` and positional `%1$d` are unsupported (the last is #3569). Only Windows was built and run; the Linux glibc path still prints `%D`, `%O`, `%U` and unknown conversions as written. The reference is the FreeBSD source, not a console. AI-assisted: yes
xXPBSXx commented 2026-10-12 07:22:23 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T07:22:23Z.


Windows test of the fix branch (husseinkad:fix/libc-format-freebsd-conversions, 0e3b2896d + 0106858d3) merged onto current upstream/main d146ec1b6 (Windows 10, WinLibs GCC 15.2, Release; built guest_formatting_tests, guest_wide_formatting_tests, file_streams_tests, guest_standard_stream_tests):

  • guest_wide_formatting, file_streams and guest_standard_streams pass.
  • guest_formatting fails (Formatting check failed at core/libs/tests/Formatting.cpp:187, the loop over the formats that must still throw). The format that no longer throws is %1$d: main now handles positional arguments (#3569, b9fc44834), and also the ' flag (#3567, d9fe7ee61), so the branch's list {"%m", "%1$d", "%'d", ...} is stale. With "%1$d" and "%'d" removed from that list locally (nothing else changed), all four tests pass, including the new %qd, %D/%O/%U, unknown-conversion and trailing-% cases. python tools/check_conventions.py --base upstream/main passes on the merge.
  • Semantics against FreeBSD 11.4 lib/libc/stdio/vfprintf.c (releng/11.4): case 'q' sets LLONGINT, D/O/U set LONGINT and fall through to d/o/u, and the default case prints the character itself and stops on NUL (goto done); that matches the branch's behaviour as I read it. I did not rerun the reporter's differential fuzz.

So the branch needs the two stale entries dropped from the test list before it can go in on current main. Not tested: Linux.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6119651017 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3975#issuecomment-6119651017). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-12T07:22:23Z. --- Windows test of the fix branch (`husseinkad:fix/libc-format-freebsd-conversions`, `0e3b2896d` + `0106858d3`) merged onto current upstream/main `d146ec1b6` (Windows 10, WinLibs GCC 15.2, Release; built `guest_formatting_tests`, `guest_wide_formatting_tests`, `file_streams_tests`, `guest_standard_stream_tests`): - `guest_wide_formatting`, `file_streams` and `guest_standard_streams` pass. - `guest_formatting` fails (`Formatting check failed` at `core/libs/tests/Formatting.cpp:187`, the loop over the formats that must still throw). The format that no longer throws is `%1$d`: main now handles positional arguments (#3569, `b9fc44834`), and also the `'` flag (#3567, `d9fe7ee61`), so the branch's list `{"%m", "%1$d", "%'d", ...}` is stale. With `"%1$d"` and `"%'d"` removed from that list locally (nothing else changed), all four tests pass, including the new `%qd`, `%D/%O/%U`, unknown-conversion and trailing-`%` cases. `python tools/check_conventions.py --base upstream/main` passes on the merge. - Semantics against FreeBSD 11.4 `lib/libc/stdio/vfprintf.c` (releng/11.4): `case 'q'` sets `LLONGINT`, `D`/`O`/`U` set `LONGINT` and fall through to `d`/`o`/`u`, and the default case prints the character itself and stops on NUL (`goto done`); that matches the branch's behaviour as I read it. I did not rerun the reporter's differential fuzz. So the branch needs the two stale entries dropped from the test list before it can go in on current main. Not tested: Linux. AI-assisted (Claude Code).
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#3975
No description provided.