Fix paragraph layouting index out of bounds bug (#3607)

This commit is contained in:
frozolotl 2024-03-11 11:35:39 +01:00 committed by GitHub
parent 443cf60ae2
commit 6e0b3484dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 9 deletions

View File

@ -244,6 +244,8 @@ impl<'a> FlowLayouter<'a> {
)?
.into_frames();
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 {
@ -253,8 +255,6 @@ impl<'a> FlowLayouter<'a> {
}
}
if let Some(first) = lines.first() {
while !self.regions.size.y.fits(first.height()) && !self.regions.in_last() {
let carry: Vec<_> = self.items.drain(sticky..).collect();
self.finish_region(engine, false)?;
for item in carry {

BIN
tests/ref/bugs/flow-5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

13
tests/typ/bugs/flow-5.typ Normal file
View File

@ -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)