Skip to content

engine: bound a runaway argument grabbed at end of file - #19

Merged
tannevaled merged 1 commit into
mainfrom
fix-runaway-arg-eof
Aug 17, 2026
Merged

tannevaled merged 1 commit into
mainfrom
fix-runaway-arg-eof

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

The bug

Every aastex*/revtex4-* paper (54+ in the arXiv corpus) hangs on the current main. Minimal repro:

\documentclass{aastex701}
\begin{document}
Hello.
\end{document}

Root cause

#12 (the beamer PR) made \IfFormatAtLeastTF answer correctly and added the 2020 hook system. As a side effect, aastex701's \rvtx@ifformat@geq{2020/10/01} now takes the newer-LaTeX branch, which does \AddToHook{enddocument}{\rvtx@enddocument@patch{}}.

\rvtx@enddocument@patch has parameter text #1#2\@checkend#3: it scans forward for \@checkend{document} to reorder \check@aux. The engine's simplified \enddocument never emits \@checkend{document}, so the patch's @more branch re-grabs an ever-growing argument, forever, with the mouth already at end of file.

The expansion guard (stepOverrun) never fires because the churn is in argument grabbing, not macro expansion, and no base input is consumed — so it is not a "runaway expansion" as the engine currently defines one.

The fix

Charge each grabbed token (in grabDelimited/grabUntilBrace/grabGroup) to the same no-progress guard. While a grab reads new base input the counter resets, so an ordinary — even very large — argument never trips; an argument assembled entirely from re-pushed tokens at end of file does. A hard maxArgToks ceiling backs it up. On a trip, tripRunaway unwinds the input so the document built so far still renders (partial output) instead of hanging.

Verification

  • New TestRunawayDelimitedArgAtEOF — proven red (20 s timeout) without the fix, green (0.11 s) with it.
  • Full suite green, gofmt clean.
  • 12/12 sampled aastex/mnras papers now terminate (all hung before); 6 diverse non-aastex papers produce identical page counts to the previous release (no regression).

This is complementary to #17 (file-end-sentinel runaway): that catches an argument scan overrunning a file boundary; this catches one churning at true end of file. They compose cleanly (verified).

🤖 Generated with Claude Code

A delimited macro-argument scan that never finds its delimiter and re-pushes a
growing argument each round is a runaway the expansion guard alone never caught:
the churn is in grabbing an argument, not expanding a macro, and the mouth is
already at end of file, so no base input is consumed. Every aastex/revtex paper
hung on it. The 2020 LaTeX format's enddocument hook (now that \IfFormatAtLeast
answers correctly) installs \rvtx@enddocument@patch — parameter text
"#1#2\@Checkend#3" — which hunts for a \@Checkend{document} the engine's
simplified \enddocument never emits, re-grabbing an ever-growing argument until
memory is exhausted.

Charge each grabbed token to the same no-progress guard that catches a
self-expanding macro (stepOverrun): while a grab reads new base input the counter
resets, so an ordinary — even very large — argument never trips, but an argument
assembled entirely from re-pushed tokens at end of file does. A hard maxArgToks
ceiling backs it up. When either trips, tripRunaway unwinds the input, so the
document built so far still renders instead of hanging.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@tannevaled
tannevaled merged commit 0e6bd16 into main Aug 17, 2026
13 of 18 checks passed
@tannevaled
tannevaled deleted the fix-runaway-arg-eof branch August 17, 2026 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant