Skip to content

Commit

Permalink
Fix infinite loop + memory leak when flattening a segment with a NaN …
Browse files Browse the repository at this point in the history
…point.
  • Loading branch information
Fincap committed Aug 8, 2024
1 parent f4196d7 commit 225129c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,16 @@ impl Segment {
}
result
}

pub fn is_nan(&self) -> bool {
match self {
Segment::Line(line) => line.0.as_slice(),
Segment::Quad(quad) => quad.0.as_slice(),
Segment::Cubic(cubic) => cubic.0.as_slice(),
}
.iter()
.any(|point| point.0.iter().any(|f| f.is_nan()))
}
}

impl fmt::Debug for Segment {
Expand Down
3 changes: 3 additions & 0 deletions src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,9 @@ impl<'a> Iterator for PathFlattenIter<'a> {
loop {
match self.stack.pop() {
Some(segment) => {
if segment.is_nan() {
panic!("cannot flatten segment with NaN");
}
if segment.flatness() < self.flatness {
return Some(Line::new(segment.start(), segment.end()));
}
Expand Down

0 comments on commit 225129c

Please sign in to comment.