summaryrefslogtreecommitdiff
path: root/crates/typst-library/src/layout/grid.rs
diff options
context:
space:
mode:
authorbluebear94 <uruwi@protonmail.com>2023-10-05 04:26:36 -0400
committerGitHub <noreply@github.com>2023-10-05 10:26:36 +0200
commit6bb776029e5d3261bd79605f91eb1e7fd14d06ea (patch)
tree17c6f352d848731309580c3dbe0c9f08304d7b38 /crates/typst-library/src/layout/grid.rs
parentea0f22a8ca2eec4bde44fc4afc6032c2728aed27 (diff)
Fix crashes with infinite lengths (part 2) (#2298)
Diffstat (limited to 'crates/typst-library/src/layout/grid.rs')
-rw-r--r--crates/typst-library/src/layout/grid.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/crates/typst-library/src/layout/grid.rs b/crates/typst-library/src/layout/grid.rs
index 134bdc7c..8d015782 100644
--- a/crates/typst-library/src/layout/grid.rs
+++ b/crates/typst-library/src/layout/grid.rs
@@ -114,6 +114,7 @@ impl Layout for GridElem {
&cells,
regions,
styles,
+ self.span(),
);
// Measure the columns and layout the grid row-by-row.
@@ -161,6 +162,8 @@ pub struct GridLayouter<'a> {
initial: Size,
/// Frames for finished regions.
finished: Vec<Frame>,
+ /// The span of the grid element.
+ span: Span,
}
/// The resulting sizes of columns and rows in a grid.
@@ -202,6 +205,7 @@ impl<'a> GridLayouter<'a> {
cells: &'a [Content],
regions: Regions<'a>,
styles: StyleChain<'a>,
+ span: Span,
) -> Self {
let mut cols = vec![];
let mut rows = vec![];
@@ -272,6 +276,7 @@ impl<'a> GridLayouter<'a> {
lrows: vec![],
initial: regions.size,
finished: vec![],
+ span,
}
}
@@ -563,6 +568,10 @@ impl<'a> GridLayouter<'a> {
height: Abs,
y: usize,
) -> SourceResult<Frame> {
+ if !height.is_finite() {
+ bail!(error!(self.span, "cannot create grid with infinite height"));
+ }
+
let mut output = Frame::soft(Size::new(self.width, height));
let mut pos = Point::zero();