Deeply nested emphasis is quadratic and overflows the stack in the lexer
I maintainer di solito rispondono entro 4 giorni
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 25/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Ferma
- Stack tecnologico
- node.js, typescript
- Ambito
- backend, performance
Direzione di ricerca
The report identifies recursion from emStrong to inlineTokens and repeated lexing of nested text, but does not name source or test files. Start by tracing that call path and inspect the existing emphasis tests and lexer benchmarks. The issue is resolved when deeply nested emphasis lexes in linear time without stack overflow, with regression tests covering both behaviors.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Marked version: 18.3.0 (also 17.0.6), Node 22.23.5, default options
Describe the bug
Properly nested emphasis lexes in superlinear (roughly quadratic) time, and past a depth that depends on the stack size marked.lexer() throws RangeError: Maximum call stack size exceeded. A few kilobytes of input are enough, so any application that lexes user-supplied Markdown can be stalled or made to throw.
To Reproduce
npm install [email protected]- Run:
import { marked } from "marked";
for (const n of [300, 600, 1200, 1500, 2000]) {
const src = "*a ".repeat(n) + "b" + " c*".repeat(n);
const start = process.cpuUsage();
try {
marked.lexer(src);
const used = process.cpuUsage(start);
console.log(n, (used.user + used.system) / 1000, "ms");
} catch (e) {
console.log(n, e.constructor.name, e.message);
}
}
- Actual output (CPU ms per
marked.lexer, best of 3):
| nesting levels | 300 | 600 | 1,200 | 1,500 | 2,000 |
|---|---|---|---|---|---|
| marked 18.3.0 | 39 | 141 | 589 | 851 | RangeError: Maximum call stack size exceeded |
The stack shows the lexer recursing emStrong → inlineTokens once per nesting level and re-lexing the inner text each time, which explains both the quadratic time and a recursion depth equal to the nesting depth. On 17.0.6 the same input also overflows the stack (by 3,000 levels).
Expected behavior
Linear time and no stack overflow, as with CommonMark's delimiter-stack algorithm. For comparison, markdown-it-py 4.3.0 renders the same input in 23 ms at 1,200 levels and 543 ms at 20,000 levels, without overflowing.
(The unclosed-delimiter case, "*a ".repeat(n), is already fast on 18.3.0; thanks for that fix.)
- Lingua principale
- TypeScript
- Stelle
- 37.3k
- Fork
- 3.9k
- Merge medio
- 5g 6h
- PR unite (30g)
- 62
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di markedjs/marked
-
Inline raw HTML is escaped after an unclosed `_` / `*` / `~` (regression in 18.2.1)Forse già presa @O1sumitkumar l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 4 giorni
-
Lazy continuation line inside a quoted list item is parsed as a nested listForse già presa @amstedy l’ha presa 1 giorno fa. ApertaL2 - annoying
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
markedjs/marked#4293 · 2 commenti ·
I maintainer di solito rispondono entro 4 giorni
-
proposal
Difficoltà 5/5 Più di una settimana Idoneità per principianti 22/100
markedjs/marked#4282 · 8 commenti ·
I maintainer di solito rispondono entro 4 giorni
-
Quadratic time in the inline `text` rule: its email look-ahead rereads the rest of the paragraphForse già presa @yxshee l’ha presa 10 giorni fa. ApertaL2 - annoying
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
I maintainer di solito rispondono entro 4 giorni
-
List item ends at a lazy line after a paragraph line indented 4+ columnsForse già presa @hakarrr l’ha presa 14 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
I maintainer di solito rispondono entro 4 giorni
Tutte le issue di markedjs/marked
Issue simili
-
[Bug]: A Markdown link with both a :line suffix and a #L fragment opens a path containing ":line"Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
status:needs-triage type:bug workstream:refimpl
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
GenAI-Security-Project/agent-control-standard#764 ·
I maintainer di solito rispondono entro 1 giorno
-
good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
TanbirRamim/vibereel#39 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
lingdojo/kana-dojo#34988 · 1 commento · 5 reazioni ·
I maintainer di solito rispondono entro 1 giorno