Skip to content

Version 13 , old rendering behavior, combined with a large number of execution calls, will lead to an "Maximum call stack size exceeded" error #3379

@yijian166

Description

@yijian166

Marked version: 13

Describe the bug

as title, code will throw "Maximum call stack size exceeded" error

To Reproduce

  1. npm install --save marked@13.0.2
  2. run code like below
const marked = require('marked')

const content = '\n## 1. some title\n\nsimple content'

marked.use({
	renderer: {
		heading(text, level) {
			const escapedText = encodeURIComponent(text).replaceAll('%', '.');
			return `<h${level} id="${escapedText}">
									${text}
					</h${level}>`;
					
		},
	},
});

for (const _ of new Array(10000).fill(0)) {
	marked.parse(content);
}
  1. code will throw error "RangeError: Maximum call stack size exceeded"
image

some code dig

As I read through the code, it seems that, in simple terms, reassignment rendererFunc leads to recursive-like calls (each execution results in an additional call).

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions