From 39e41ba3c6e8b78324f30b6513c81f31b84472d9 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 26 Nov 2024 12:39:00 +0000 Subject: [PATCH] Fix `path` with infinite length causing panic (#5457) --- crates/typst-layout/src/shapes.rs | 4 ++++ tests/suite/visualize/line.typ | 4 ++++ tests/suite/visualize/path.typ | 4 ++++ tests/suite/visualize/polygon.typ | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/crates/typst-layout/src/shapes.rs b/crates/typst-layout/src/shapes.rs index 81be12190..a35021721 100644 --- a/crates/typst-layout/src/shapes.rs +++ b/crates/typst-layout/src/shapes.rs @@ -114,6 +114,10 @@ pub fn layout_path( path.close_path(); } + if !size.is_finite() { + bail!(elem.span(), "cannot create path with infinite length"); + } + // Prepare fill and stroke. let fill = elem.fill(styles); let fill_rule = elem.fill_rule(styles); diff --git a/tests/suite/visualize/line.typ b/tests/suite/visualize/line.typ index 7259f72ba..6cbbbb493 100644 --- a/tests/suite/visualize/line.typ +++ b/tests/suite/visualize/line.typ @@ -90,3 +90,7 @@ --- line-bad-point-component-type --- // Error: 14-26 expected relative length, found angle #line(start: (3deg, 10pt), length: 5cm) + +--- line-infinite-length --- +// Error: 2-54 cannot create line with infinite length +#line(start: (0pt, 0pt), end: (float.inf * 1pt, 0pt)) diff --git a/tests/suite/visualize/path.typ b/tests/suite/visualize/path.typ index 95f7a803c..55c0f5340 100644 --- a/tests/suite/visualize/path.typ +++ b/tests/suite/visualize/path.typ @@ -71,6 +71,10 @@ // Error: 7-31 point array must contain exactly two entries #path(((0%, 0%), (0%, 0%, 0%))) +--- path-infinite-length --- +// Error: 2-42 cannot create path with infinite length +#path((0pt, 0pt), (float.inf * 1pt, 0pt)) + --- issue-path-in-sized-container --- // Paths used to implement `LayoutMultiple` rather than `LayoutSingle` without // fulfilling the necessary contract of respecting region expansion. diff --git a/tests/suite/visualize/polygon.typ b/tests/suite/visualize/polygon.typ index 7d8342c8e..ec27194df 100644 --- a/tests/suite/visualize/polygon.typ +++ b/tests/suite/visualize/polygon.typ @@ -51,3 +51,7 @@ --- polygon-bad-point-array --- // Error: 10-17 point array must contain exactly two entries #polygon((50pt,)) + +--- polygon-infinite-size --- +// Error: 2-57 cannot create polygon with infinite size +#polygon((0pt, 0pt), (0pt, 1pt), (float.inf * 1pt, 0pt))