Deeply nested emphasis is quadratic and overflows the stack in the lexer
Los mantenedores suelen responder en 4 días
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 25/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Estancado
- Stack tecnológico
- node.js, typescript
- Área
- backend, performance
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.)
- Lenguaje dominante
- TypeScript
- Estrellas
- 37.3k
- Forks
- 3.9k
- Merge medio
- 5 d 6 h
- PR fusionados (30 d)
- 62
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de markedjs/marked
-
Inline raw HTML is escaped after an unclosed `_` / `*` / `~` (regression in 18.2.1)Posiblemente ocupada @O1sumitkumar la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 4 días
-
Lazy continuation line inside a quoted list item is parsed as a nested listPosiblemente ocupada @amstedy la tomó hace 1 día. AbiertoL2 - annoying
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
markedjs/marked#4293 · 2 comentarios ·
Los mantenedores suelen responder en 4 días
-
proposal
Dificultad 5/5 Más de una semana Aptitud para principiantes 22/100
markedjs/marked#4282 · 8 comentarios ·
Los mantenedores suelen responder en 4 días
-
Quadratic time in the inline `text` rule: its email look-ahead rereads the rest of the paragraphPosiblemente ocupada @yxshee la tomó hace 10 días. AbiertoL2 - annoying
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
Los mantenedores suelen responder en 4 días
-
List item ends at a lazy line after a paragraph line indented 4+ columnsPosiblemente ocupada @hakarrr la tomó hace 14 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
Los mantenedores suelen responder en 4 días
Todos los issues de markedjs/marked
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día
-
Make the "%" unit spacing the same in the web and in A10Posiblemente ocupada @kragent66-glitch la tomó hoy. Abiertobug good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
maiychrus25/OpenTea-DX-OS#226 · 1 comentario ·
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
nextcloud-libraries/nextcloud-dialogs#2772 ·
Los mantenedores suelen responder en 1 día
-
Editor: leave an uploaded or inserted image's alt text empty, so the preview asks for a descriptionAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 65/100
sveltejs/svelte.dev#2417 ·
Los mantenedores suelen responder en 1 día