Never crash: PDF close-path operators and CFF outlines without a current point
The s, b and b* operators closed the path even when there was no current point, which kurbo asserts against (a panic in debug builds; found by fuzzing). Close only when a subpath is open. CFF charstrings that draw before their first rmoveto now start the subpath at the current point, as Type 1 charstrings already did. Denies the panic lints in the crate (it had no panic sites). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
10644a83aa
commit
8e4e29844e
+10
-3
@@ -332,7 +332,7 @@ impl<'a> Interp<'a> {
|
||||
// Painting.
|
||||
"S" => self.paint(false, None, true, depth),
|
||||
"s" => {
|
||||
self.path.close_path();
|
||||
self.close_subpath();
|
||||
self.paint(false, None, true, depth)
|
||||
}
|
||||
"f" | "F" => self.paint(true, Some(FillRule::NonZero), false, depth),
|
||||
@@ -340,11 +340,11 @@ impl<'a> Interp<'a> {
|
||||
"B" => self.paint(true, Some(FillRule::NonZero), true, depth),
|
||||
"B*" => self.paint(true, Some(FillRule::EvenOdd), true, depth),
|
||||
"b" => {
|
||||
self.path.close_path();
|
||||
self.close_subpath();
|
||||
self.paint(true, Some(FillRule::NonZero), true, depth)
|
||||
}
|
||||
"b*" => {
|
||||
self.path.close_path();
|
||||
self.close_subpath();
|
||||
self.paint(true, Some(FillRule::EvenOdd), true, depth)
|
||||
}
|
||||
"n" => self.paint(false, None, false, depth),
|
||||
@@ -549,6 +549,13 @@ impl<'a> Interp<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Close the current subpath; nothing to close without a current point.
|
||||
fn close_subpath(&mut self) {
|
||||
if self.cur.is_some() {
|
||||
self.path.close_path();
|
||||
}
|
||||
}
|
||||
|
||||
fn ensure_start(&mut self) {
|
||||
if self.cur.is_none() {
|
||||
self.path.move_to((0.0, 0.0));
|
||||
|
||||
Reference in New Issue
Block a user