Skip to content

Commit

Permalink
[read-fonts] var: fix overflow in packed point numbers (#1285)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfrg authored Dec 10, 2024
1 parent ae22bd6 commit f82e95f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion read-fonts/src/tables/variations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ impl Iterator for PackedPointNumbersIter<'_> {
return None;
}
self.seen += 1;
self.last_val += self.current_run.next()?;
self.last_val = self.last_val.checked_add(self.current_run.next()?)?;
Some(self.last_val)
}

Expand Down Expand Up @@ -1491,4 +1491,15 @@ mod tests {
let expected_len = 2 * row_len;
assert_eq!(ivs.delta_sets().len(), expected_len);
}

// Add with overflow when accumulating packed point numbers
// https://issues.oss-fuzz.com/issues/378159154
#[test]
fn packed_point_numbers_avoid_overflow() {
// Lots of 1 bits triggers the behavior quite nicely
let buf = vec![0xFF; 0xFFFF];
let iter = PackedPointNumbersIter::new(0xFFFF, FontData::new(&buf).cursor());
// Don't panic!
let _ = iter.count();
}
}

0 comments on commit f82e95f

Please sign in to comment.