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: avoid overflow in INSTCTRL #1202

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
21 changes: 20 additions & 1 deletion skrifa/src/outline/glyf/hint/engine/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,9 +561,15 @@ impl<'a> Engine<'a> {
let selector = self.value_stack.pop()? as u32;
let value = self.value_stack.pop()? as u32;
// Selectors are indices starting with 1; not flags.
// Avoid potential subtract with overflow below.
// See <https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=70426>
// and <https://oss-fuzz.com/testcase?key=6243979511791616>
if !(1..=3).contains(&selector) {
return Ok(());
}
// Convert index to flag.
let selector_flag = 1 << (selector - 1);
if !(1..=3).contains(&selector) || (value != 0 && value != selector_flag) {
if value != 0 && value != selector_flag {
return Ok(());
}
// If preserving linear metrics, prevent modification of the backward
Expand Down Expand Up @@ -1112,6 +1118,19 @@ mod tests {
assert!(engine.graphics.backward_compatibility);
}

// Subtract with overflow caught by fuzzing when selector == 0
// See <https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=70426>
// and <https://oss-fuzz.com/testcase?key=6243979511791616>
#[test]
fn instctrl_avoid_overflow() {
let mut mock = MockEngine::new();
let mut engine = mock.engine();
engine.program.initial = Program::ControlValue;
engine.value_stack.push(0).unwrap();
engine.value_stack.push(0).unwrap();
engine.op_instctrl().unwrap();
}

#[test]
fn scanctrl() {
let mut mock = MockEngine::new();
Expand Down