Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

markdown_preview: Prevent stackoverflows in markdown parsing (#51637)

Lukas Wirtha93c66e79475
diff --git a/Cargo.lock b/Cargo.lock
index 8d86e9fa9b8..83606c7414b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -10247,6 +10247,7 @@ dependencies = [
"pretty_assertions",
"pulldown-cmark 0.13.0",
"settings",
+ "stacksafe",
"theme",
"ui",
"urlencoding",
diff --git a/crates/markdown_preview/Cargo.toml b/crates/markdown_preview/Cargo.toml
index 4baa308f108..c72de7274a4 100644
--- a/crates/markdown_preview/Cargo.toml
+++ b/crates/markdown_preview/Cargo.toml
@@ -30,6 +30,7 @@ markup5ever_rcdom.workspace = true
pretty_assertions.workspace = true
pulldown-cmark.workspace = true
settings.workspace = true
+stacksafe.workspace = true
theme.workspace = true
ui.workspace = true
urlencoding.workspace = true
diff --git a/crates/markdown_preview/src/markdown_parser.rs b/crates/markdown_preview/src/markdown_parser.rs
index ffd697d0e1b..29ea273f495 100644
--- a/crates/markdown_preview/src/markdown_parser.rs
+++ b/crates/markdown_preview/src/markdown_parser.rs
@@ -10,6 +10,7 @@ use language::LanguageRegistry;
use markdown::parser::PARSE_OPTIONS;
use markup5ever_rcdom::RcDom;
use pulldown_cmark::{Alignment, Event, Parser, Tag, TagEnd};
+use stacksafe::stacksafe;
use std::{
cell::RefCell, collections::HashMap, mem, ops::Range, path::PathBuf, rc::Rc, sync::Arc, vec,
};
@@ -907,6 +908,7 @@ impl<'a> MarkdownParser<'a> {
elements
}
+ #[stacksafe]
fn parse_html_node(
&self,
source_range: Range<usize>,
@@ -1013,6 +1015,7 @@ impl<'a> MarkdownParser<'a> {
}
}
+ #[stacksafe]
fn parse_paragraph(
&self,
source_range: Range<usize>,