Skip to content

Commit 6e58355

Browse files
committed
Avoid taking quadratic time
This avoids taking quadratic time by refusing to parse recursive chevrons and limiting nested parens to 32.
1 parent 979b0ba commit 6e58355

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/parser/inlines.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -859,13 +859,14 @@ pub fn manual_scan_link_url(input: &str) -> Option<usize> {
859859
if i < len && input.as_bytes()[i] == b'<' {
860860
i += 1;
861861
while i < len {
862-
if input.as_bytes()[i] == b'>' {
862+
let b = input.as_bytes()[i];
863+
if b == b'>' {
863864
i += 1;
864865
break;
865-
} else if input.as_bytes()[i] == b'\\' {
866+
} else if b == b'\\' {
866867
i += 2;
867-
} else if isspace(input.as_bytes()[i]) {
868-
return None;
868+
} else if isspace(b) || b == b'<' {
869+
return None
869870
} else {
870871
i += 1;
871872
}
@@ -877,6 +878,9 @@ pub fn manual_scan_link_url(input: &str) -> Option<usize> {
877878
} else if input.as_bytes()[i] == b'(' {
878879
nb_p += 1;
879880
i += 1;
881+
if nb_p > 32 {
882+
return None
883+
}
880884
} else if input.as_bytes()[i] == b')' {
881885
if nb_p == 0 {
882886
break;

0 commit comments

Comments
 (0)