Skip to content

Commit

Permalink
Avoid taking quadratic time
Browse files Browse the repository at this point in the history
This avoids taking quadratic time by refusing to parse recursive
chevrons and limiting nested parens to 32.
  • Loading branch information
DemiMarie authored and Ashe committed Aug 20, 2017
1 parent f935ec6 commit 1db99a1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/parser/inlines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -859,13 +859,14 @@ pub fn manual_scan_link_url(input: &str) -> Option<usize> {
if i < len && input.as_bytes()[i] == b'<' {
i += 1;
while i < len {
if input.as_bytes()[i] == b'>' {
let b = input.as_bytes()[i];
if b == b'>' {
i += 1;
break;
} else if input.as_bytes()[i] == b'\\' {
} else if b == b'\\' {
i += 2;
} else if isspace(input.as_bytes()[i]) {
return None;
} else if isspace(b) || b == b'<' {
return None
} else {
i += 1;
}
Expand All @@ -877,6 +878,9 @@ pub fn manual_scan_link_url(input: &str) -> Option<usize> {
} else if input.as_bytes()[i] == b'(' {
nb_p += 1;
i += 1;
if nb_p > 32 {
return None
}
} else if input.as_bytes()[i] == b')' {
if nb_p == 0 {
break;
Expand Down

0 comments on commit 1db99a1

Please sign in to comment.