Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
yijian166 opened this issue Jul 23, 2024 · 0 comments · Fixed by #3380

Comments

@yijian166
Copy link
Contributor

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant