Deeply nested emphasis is quadratic and overflows the stack in the lexer
Maintainer thường phản hồi trong vòng 4 ngày
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- node.js, typescript
- Lĩnh vực
- backend, performance
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.)
- Ngôn ngữ chính
- TypeScript
- Star
- 37.3k
- Fork
- 3.9k
- Merge trung bình
- 5 ngày 6 giờ
- Pull request đã merge (30 ngày)
- 62
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của markedjs/marked
-
Inline raw HTML is escaped after an unclosed `_` / `*` / `~` (regression in 18.2.1)Có thể đã có người làm @O1sumitkumar đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 4 ngày
-
Lazy continuation line inside a quoted list item is parsed as a nested listCó thể đã có người làm @amstedy đã nhận 1 ngày trước. Đang mởL2 - annoying
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
markedjs/marked#4293 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 4 ngày
-
proposal
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 22/100
markedjs/marked#4282 · 8 bình luận ·
Maintainer thường phản hồi trong vòng 4 ngày
-
Quadratic time in the inline `text` rule: its email look-ahead rereads the rest of the paragraphCó thể đã có người làm @yxshee đã nhận 10 ngày trước. Đang mởL2 - annoying
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
Maintainer thường phản hồi trong vòng 4 ngày
-
List item ends at a lazy line after a paragraph line indented 4+ columnsCó thể đã có người làm @hakarrr đã nhận 15 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
Maintainer thường phản hồi trong vòng 4 ngày
Tất cả issue của markedjs/marked
Issue tương tự
-
Media browser returns "Not found" for repositories using the SHA-256 object formatCó thể đã có người làm @adamchodera đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Follow-ups from #312Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
janhesters/remixcn#318 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Interceptor LaunchTestProfile.sh: no Windows (Git Bash/MSYS) branch, test profile never launchesĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
danielmiessler/LifeOS#3150 ·
Maintainer thường phản hồi trong vòng 5 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Make the "%" unit spacing the same in the web and in A10Có thể đã có người làm @kragent66-glitch đã nhận hôm nay. Đang mởbug good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
maiychrus25/OpenTea-DX-OS#226 · 1 bình luận ·