Browse Source
The opener stack is capped at MAX_OPENERS (1000) to bound memory on malicious input. Reaching the cap returned from process_inlines(), which abandoned the whole inline token stream: every replacement collected so far was dropped, and no quote later in the paragraph was converted. A document only has to contain 1000 unmatched opening quotes before an otherwise ordinary quote or apostrophe stops being typographed, and the paragraph's already-resolved pairs revert to straight quotes too. Stop pushing new openers past the cap instead of returning. Pairs that resolved earlier keep their replacements, apostrophes further on are still converted, and the memory bound is unchanged: the stack still never exceeds MAX_OPENERS entries. Timing on the existing pathological patterns is unchanged and stays linear (200k unmatched openers: ~53ms, 4x input -> ~3.5x time).pull/1211/head
2 changed files with 31 additions and 12 deletions
Loading…
Reference in new issue