Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[skrifa] tthint: fix overflow in flip region instruction #1284

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions skrifa/src/outline/glyf/hint/engine/outline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,10 +833,13 @@ impl Engine<'_> {

/// Helper for FLIPRGON and FLIPRGOFF.
fn set_on_curve_for_range(&mut self, on: bool) -> OpResult {
let high_point = self.value_stack.pop_usize()?;
let low_point = self.value_stack.pop_usize()?;
// high_point is inclusive but Zone::set_on_curve takes an exclusive
// range
let high_point = self.value_stack.pop_usize()? + 1;
let low_point = self.value_stack.pop_usize()?;
let high_point = high_point
.checked_add(1)
.ok_or(HintErrorKind::InvalidPointIndex(high_point))?;
// In backward compatibility mode, don't flip points after IUP has
// been done.
if self.graphics.backward_compatibility
Expand Down Expand Up @@ -1385,6 +1388,18 @@ mod tests {
assert!(engine.graphics.did_iup_y);
}

// Add with overflow caught by fuzzer:
// https://issues.oss-fuzz.com/issues/377736138
#[test]
fn flip_region_avoid_overflow() {
let mut mock = MockEngine::new();
let mut engine = mock.engine();
engine.value_stack.push(1).unwrap();
engine.value_stack.push(-1).unwrap();
// Just don't panic
let _ = engine.set_on_curve_for_range(true);
}

fn set_test_vectors(engine: &mut Engine) {
let v = math::normalize14(100, 50);
engine.graphics.proj_vector = v;
Expand Down
Loading