Repository navigation
engine: bound a runaway argument grabbed at end of file - #19
Merged
Merged
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
Every
aastex*/revtex4-*paper (54+ in the arXiv corpus) hangs on the currentmain. Minimal repro:Root cause
#12(the beamer PR) made\IfFormatAtLeastTFanswer 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@patchhas parameter text#1#2\@checkend#3: it scans forward for\@checkend{document}to reorder\check@aux. The engine's simplified\enddocumentnever emits\@checkend{document}, so the patch's@morebranch 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 hardmaxArgToksceiling backs it up. On a trip,tripRunawayunwinds the input so the document built so far still renders (partial output) instead of hanging.Verification
TestRunawayDelimitedArgAtEOF— proven red (20 s timeout) without the fix, green (0.11 s) with it.gofmtclean.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