diff --git a/read-fonts/src/tables/variations.rs b/read-fonts/src/tables/variations.rs index 7f692c9b8..41c37c7eb 100644 --- a/read-fonts/src/tables/variations.rs +++ b/read-fonts/src/tables/variations.rs @@ -362,7 +362,7 @@ impl Iterator for PackedPointNumbersIter<'_> { // if our count is zero, we keep incrementing forever if self.count == 0 { let result = self.last_val; - self.last_val += 1; + self.last_val = self.last_val.checked_add(1)?; return Some(result); } @@ -827,4 +827,13 @@ mod tests { assert_eq!(points.total_len(), 4); assert_eq!(data.len(), INPUT.len() - 4); } + + #[test] + fn packed_points_dont_panic() { + // a single '0' byte means that there are deltas for all points + static ALL_POINTS: FontData = FontData::new(&[0]); + let (all_points, _) = PackedPointNumbers::split_off_front(ALL_POINTS); + // in which case the iterator just keeps incrementing until u16::MAX + assert_eq!(all_points.iter().count(), u16::MAX as _); + } }