summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrozolotl <44589151+frozolotl@users.noreply.github.com>2024-03-11 11:35:39 +0100
committerGitHub <noreply@github.com>2024-03-11 10:35:39 +0000
commit6e0b3484dd0360eef5365ce23144bfc59ade89ba (patch)
tree7ce11742aa4a0d584d18ed95ada5ad7f1ab98adc
parent443cf60ae21d7d638a3279b64e22f6beb3a5f1b0 (diff)
Fix paragraph layouting index out of bounds bug (#3607)
-rw-r--r--crates/typst/src/layout/flow.rs18
-rw-r--r--tests/ref/bugs/flow-5.pngbin0 -> 20421 bytes
-rw-r--r--tests/typ/bugs/flow-5.typ13
3 files changed, 22 insertions, 9 deletions
diff --git a/crates/typst/src/layout/flow.rs b/crates/typst/src/layout/flow.rs
index bd693bd8..85f67142 100644
--- a/crates/typst/src/layout/flow.rs
+++ b/crates/typst/src/layout/flow.rs
@@ -244,17 +244,17 @@ impl<'a> FlowLayouter<'a> {
)?
.into_frames();
- let mut sticky = self.items.len();
- for (i, item) in self.items.iter().enumerate().rev() {
- match *item {
- FlowItem::Absolute(_, _) => {}
- FlowItem::Frame { sticky: true, .. } => sticky = i,
- _ => break,
- }
- }
-
if let Some(first) = lines.first() {
while !self.regions.size.y.fits(first.height()) && !self.regions.in_last() {
+ let mut sticky = self.items.len();
+ for (i, item) in self.items.iter().enumerate().rev() {
+ match *item {
+ FlowItem::Absolute(_, _) => {}
+ FlowItem::Frame { sticky: true, .. } => sticky = i,
+ _ => break,
+ }
+ }
+
let carry: Vec<_> = self.items.drain(sticky..).collect();
self.finish_region(engine, false)?;
for item in carry {
diff --git a/tests/ref/bugs/flow-5.png b/tests/ref/bugs/flow-5.png
new file mode 100644
index 00000000..648c8c44
--- /dev/null
+++ b/tests/ref/bugs/flow-5.png
Binary files differ
diff --git a/tests/typ/bugs/flow-5.typ b/tests/typ/bugs/flow-5.typ
new file mode 100644
index 00000000..5e580b9e
--- /dev/null
+++ b/tests/typ/bugs/flow-5.typ
@@ -0,0 +1,13 @@
+// This bug caused an index-out-of-bounds panic when layouting paragraphs needed
+// multiple reorderings.
+
+---
+#set page(height: 200pt)
+#lorem(30)
+
+#figure(placement: auto, block(height: 100%))
+
+#lorem(10)
+
+#lorem(10)
+