Skip to content

fix(libc): accept printf argument positions above 99 - #9552

Closed
DavidSamir wants to merge 2 commits into
boykopovar:mainfrom
DavidSamir:fix/libc-printf-positions-past-99
Closed

DavidSamir wants to merge 2 commits into
boykopovar:mainfrom
DavidSamir:fix/libc-printf-positions-past-99

Conversation

@DavidSamir

@DavidSamir DavidSamir commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

What

The guest printf formatter (WindowsFormatting.hpp, used by the narrow and wide printf families whenever a format needs the guest formatter) threw for any argument position above 99, such as %100$d. FreeBSD 11's vfprintf has no such limit:

  • The position: it is parsed as a plain int (lib/libc/stdio/vfprintf.c:563-575).
  • The table: __find_arguments grows the argument type table for any position (lib/libc/stdio/printf-pos.c:622, __grow_type_table).
  • NL_ARGMAX 99 (include/limits.h:123) is only the advertised minimum; nothing enforces it.

Here the argument table is already a growable vector, so the cap was the only limit. maximumArgumentPosition is now INT_MAX, where FreeBSD's int position would overflow. Position 0 and positions above INT_MAX still throw.

The two libc.md sentences that named the 99 limit (the narrow printf family and %p) now say INT_MAX. Those are minimal edits, because #8855 rewrites the same sentences; whichever merges second keeps the INT_MAX wording.

Tested

Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release. This is CPU-side, so no GPU is involved.

guest_formatting (core/libs/tests/Formatting.cpp) changes:

  • %100$d%ls passes now: it moves from the invalid-position list to a passing check with 121 arguments, "%120$d|%1$d|%100$d|%121$ls", which gives 120|1|100|x.
  • A new invalid case: %2147483648$d%ls (above INT_MAX) joins the list, which keeps %0$d%ls and %*0$d%ls.

Results:

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none (order with fix(libc): convert multibyte text as UTF-8 like the console's C locale #8855 agreed with its author: neither waits; whichever merges second keeps both libc.md sentence changes)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

FreeBSD's vfprintf grows its argument type table for any position
(printf-pos.c __grow_type_table); NL_ARGMAX 99 is only an advertised
constant. Positions are now refused only above INT_MAX, where
FreeBSD's int position would overflow.
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 3965 docs/dev/debt/libc.md
PR 5021 core/libs/prx/libc/include/WindowsFormatting.hpp
core/libs/tests/Formatting.cpp
docs/dev/debt/libc.md
PR 5303 docs/dev/debt/libc.md
PR 6565 docs/dev/debt/libc.md
PR 6713 docs/dev/debt/libc.md
PR 6819 docs/dev/debt/libc.md
PR 7081 docs/dev/debt/libc.md
PR 7201 core/libs/tests/Formatting.cpp
PR 7386 core/libs/tests/Formatting.cpp
docs/dev/debt/libc.md
PR 7447 docs/dev/debt/libc.md
PR 7544 docs/dev/debt/libc.md
PR 7648 docs/dev/debt/libc.md
PR 7715 docs/dev/debt/libc.md
PR 8150 docs/dev/debt/libc.md
PR 8397 docs/dev/debt/libc.md
PR 8417 docs/dev/debt/libc.md
PR 8903 docs/dev/debt/libc.md
PR 8937 docs/dev/debt/libc.md
PR 8965 docs/dev/debt/libc.md
PR 9087 core/libs/prx/libc/include/WindowsFormatting.hpp
core/libs/tests/Formatting.cpp
docs/dev/debt/libc.md
PR 9133 docs/dev/debt/libc.md
PR 9170 docs/dev/debt/libc.md
PR 9269 docs/dev/debt/libc.md
PR 9340 core/libs/tests/Formatting.cpp
docs/dev/debt/libc.md
PR 9344 docs/dev/debt/libc.md
PR 9371 docs/dev/debt/libc.md
PR 9408 docs/dev/debt/libc.md
PR 9447 docs/dev/debt/libc.md
PR 9456 docs/dev/debt/libc.md
PR 9464 docs/dev/debt/libc.md
PR 9466 docs/dev/debt/libc.md
PR 9468 docs/dev/debt/libc.md
PR 9479 core/libs/tests/Formatting.cpp
docs/dev/debt/libc.md
PR 9499 docs/dev/debt/libc.md
PR 9526 docs/dev/debt/libc.md
PR 9527 docs/dev/debt/libc.md
PR 9613 docs/dev/debt/libc.md
PR 9631 docs/dev/debt/libc.md
PR 9648 docs/dev/debt/libc.md
PR 9668 docs/dev/debt/libc.md
PR 9669 docs/dev/debt/libc.md
PR 9677 docs/dev/debt/libc.md
PR 9688 docs/dev/debt/libc.md
PR 9698 docs/dev/debt/libc.md
PR 9735 docs/dev/debt/libc.md
PR 9761 docs/dev/debt/libc.md
PR 9763 docs/dev/debt/libc.md
PR 9771 docs/dev/debt/libc.md
PR 9772 docs/dev/debt/libc.md
PR 9784 docs/dev/debt/libc.md
PR 9833 docs/dev/debt/libc.md
PR 9850 docs/dev/debt/libc.md
PR 9863 docs/dev/debt/libc.md
PR 9867 docs/dev/debt/libc.md
PR 9873 docs/dev/debt/libc.md
PR 9927 docs/dev/debt/libc.md
PR 9929 docs/dev/debt/libc.md
PR 9935 docs/dev/debt/libc.md
PR 9953 docs/dev/debt/libc.md
PR 9958 core/libs/prx/libc/include/WindowsFormatting.hpp
core/libs/tests/Formatting.cpp
docs/dev/debt/libc.md
PR 9964 docs/dev/debt/libc.md
PR 9973 docs/dev/debt/libc.md
PR 10002 docs/dev/debt/libc.md
PR 10007 docs/dev/debt/libc.md
PR 10113 docs/dev/debt/libc.md
PR 10128 docs/dev/debt/libc.md
PR 10139 docs/dev/debt/libc.md
PR 10158 docs/dev/debt/libc.md
PR 10165 docs/dev/debt/libc.md
PR 10175 docs/dev/debt/libc.md
PR 10176 docs/dev/debt/libc.md
PR 10200 docs/dev/debt/libc.md
PR 10222 docs/dev/debt/libc.md
PR 10226 docs/dev/debt/libc.md
PR 10229 docs/dev/debt/libc.md
PR 10234 docs/dev/debt/libc.md
PR 10245 docs/dev/debt/libc.md
PR 10247 docs/dev/debt/libc.md
PR 10250 docs/dev/debt/libc.md
PR 10251 docs/dev/debt/libc.md
PR 10253 docs/dev/debt/libc.md
PR 10265 docs/dev/debt/libc.md
PR 10270 docs/dev/debt/libc.md
PR 10274 docs/dev/debt/libc.md
PR 10283 docs/dev/debt/libc.md
PR 10315 docs/dev/debt/libc.md
PR 10316 docs/dev/debt/libc.md
PR 10317 docs/dev/debt/libc.md
PR 10321 docs/dev/debt/libc.md
PR 10324 docs/dev/debt/libc.md
PR 10325 docs/dev/debt/libc.md
PR 10328 docs/dev/debt/libc.md
PR 10345 docs/dev/debt/libc.md
PR 10346 docs/dev/debt/libc.md
PR 10349 docs/dev/debt/libc.md
PR 10354 docs/dev/debt/libc.md
PR 10379 core/libs/prx/libc/include/WindowsFormatting.hpp
core/libs/tests/Formatting.cpp
docs/dev/debt/libc.md
PR 10394 docs/dev/debt/libc.md
PR 10397 docs/dev/debt/libc.md
PR 10405 docs/dev/debt/libc.md
PR 10433 docs/dev/debt/libc.md
PR 10453 docs/dev/debt/libc.md
PR 10460 docs/dev/debt/libc.md
PR 10467 docs/dev/debt/libc.md
PR 10468 docs/dev/debt/libc.md
PR 10505 docs/dev/debt/libc.md
PR 10506 docs/dev/debt/libc.md
PR 10509 docs/dev/debt/libc.md
PR 10510 docs/dev/debt/libc.md
PR 10512 docs/dev/debt/libc.md
PR 10529 docs/dev/debt/libc.md
PR 10565 docs/dev/debt/libc.md
PR 10569 docs/dev/debt/libc.md
PR 10610 docs/dev/debt/libc.md
PR 10615 docs/dev/debt/libc.md
PR 10620 docs/dev/debt/libc.md
PR 10648 docs/dev/debt/libc.md
PR 10665 docs/dev/debt/libc.md
PR 10688 docs/dev/debt/libc.md
PR 10742 docs/dev/debt/libc.md
PR 10749 docs/dev/debt/libc.md
PR 10780 docs/dev/debt/libc.md
PR 10786 docs/dev/debt/libc.md
PR 10788 docs/dev/debt/libc.md
PR 10895 docs/dev/debt/libc.md
PR 10898 docs/dev/debt/libc.md
PR 10903 docs/dev/debt/libc.md
PR 10927 docs/dev/debt/libc.md
PR 10929 docs/dev/debt/libc.md
PR 10953 docs/dev/debt/libc.md
PR 10987 docs/dev/debt/libc.md
PR 10989 docs/dev/debt/libc.md
PR 11004 docs/dev/debt/libc.md
PR 11044 docs/dev/debt/libc.md
PR 11054 docs/dev/debt/libc.md

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parser bound now matches FreeBSD’s signed-int position domain, and the 121-argument positive case plus above-INT_MAX negative case exercise the stated behavior. There are two repository-process items before approval. First, #8855 is still open and edits the same debt sentences; “whichever merges second” does not record author agreement/order. Please coordinate with #8855’s author and state the agreed order (and Depends on if either must land first), preserving both debt updates. Second, this branch is based on 8c26eac3, 23 commits behind current main dce41a89478876a8e3ea9c346b1dac00bb31c8cd; please update and rerun the focused formatting tests and checks on the updated head. Hosted eligibility, conventions, intake, labels and report checks pass; relinker matrix passes and Linux/Windows product jobs are skipped. Windows results are author-reported; I did not run tests locally.

@xXPBSXx

xXPBSXx commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Linux data point for cfada08f98: WSL2 Ubuntu 24.04 (virtualised kernel, not bare-metal), GCC 13.3.0, Release, BUILD_TESTING=ON, PR head alone (not merged onto main; its merge-base is 8c26eac3c).

  • With the PR: ctest -R '^guest_formatting$' passes 3 of 3.
  • With libc/include/WindowsFormatting.hpp restored to the merge-base (the PR's tests kept): fails (Subprocess aborted).
    Not tested: macOS, Windows, a title run.
    AI-assisted (Claude Code).

@JJenkx

JJenkx commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Independent Windows run of this PR, as data only. The machine is a Ryzen 9 5950X on Windows 11 (10.0.22621), built with WinLibs GCC 15.2.0 UCRT r7, Release. I tested a local merge of your head cfada08 into main d6732b5 (8238956f91). It merged cleanly; git auto-merged docs/dev/debt/libc.md.

  • guest_formatting and guest_wide_formatting pass. These include the new 121-argument %120$d|%1$d|%100$d|%121$ls check and the %2147483648$d%ls rejection.
  • The whole libc suite passes: 143/143.

Not repeated here: your negative control with the cap back at 99.

@DavidSamir

Copy link
Copy Markdown
Contributor Author

Thanks @MarcZX10. Merged current main (d6eafa54d0) in a new merge commit 314c7c4b9c (no force-push); it merged cleanly. Rerun on that head (Windows 11, WinLibs GCC 15.2): guest_formatting and guest_wide_formatting pass; check_conventions.py reports 0 errors (its one warning is a libc debt entry already 1238 characters on main).

AI-assisted: yes

@DavidSamir

Copy link
Copy Markdown
Contributor Author

@MarcZX10 the order with #8855 is agreed: @hypermoist confirmed on #8855 that the two only meet in the narrow printf-family paragraph of docs/dev/debt/libc.md, neither depends on the other, and whichever merges second keeps both sentence changes. It's now recorded in the checklist.

AI-assisted: yes

@MarcZX10

Copy link
Copy Markdown
Contributor

The previously open merge-order point with #8855 is now resolved in the checklist, and the Windows/Linux test evidence is strong (including an independent Windows libc suite run). I refreshed the checks against current upstream/main 4777cac: diff-check passes, conventions has 0 errors with the existing long-debt warning, merge-tree is clean, but this branch is 2 ahead/11 behind (merge base d6eafa5). Please update to current main and rerun the focused formatting tests/checks before merge. The current overlap bot also identifies newly open #9699 touching the same docs/dev/debt/libc.md paragraph; please agree the merge order with that author, preserve both text changes, and record Depends on if either PR must land first. The formatter behavior appears separate. Product builds remain skipped in hosted CI; I did not run C++ tests locally because the filesystem is full.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The formatter change has good focused and independent Windows/Linux evidence, and the #8855 coordination is now recorded. Two repository requirements remain: update this branch from current upstream/main 4777cac (it is 2 ahead/11 behind, merge base d6eafa5) and rerun focused formatting tests; and record merge-order agreement with newly open #9699, which touches the same docs/dev/debt/libc.md paragraph, adding Depends on if sequencing is required. Current diff-check and conventions pass (0 errors; one inherited debt-length warning), and merge-tree is clean. Product Linux/Windows jobs are skipped; I did not run C++ tests locally due to a full filesystem.

@adriadam10

Copy link
Copy Markdown
Collaborator

Closing as superseded. main already accepts argument positions above 99 (4756ead): the position is parsed up to 65535, covered by the %100$d ... case in core/libs/tests/Formatting.cpp, and the debt entry records that up to 400 was measured on a PS5.

What is left in this PR is raising that cap to INT_MAX, which I can't take:

  • classes.resize(position) in WindowsFormatting.hpp (ArgumentPosition callers) grows the table to the requested position, so a 15-byte format like %2147483647$d would try to allocate tens of GB. The 65535 cap is the bound, and nothing here replaces it.
  • Matching FreeBSD's int domain for positions nobody can supply arguments for isn't a behaviour a title can observe, since the call can't pass that many arguments.
  • The branch also conflicts with main in code (WindowsFormatting.hpp, Formatting.cpp), not just in libc.md.

If there is a case between 65535 and INT_MAX that a real caller hits, reopen with that case and a bound on the table size.

@adriadam10 adriadam10 closed this Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs libc needs rebase Conflicts with main, rebase needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants