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: overflow in move_index stack op #1286

Merged
merged 1 commit into from
Dec 11, 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
12 changes: 11 additions & 1 deletion skrifa/src/outline/glyf/hint/value_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,11 @@ impl<'a> ValueStack<'a> {
let top_ix = self.len.checked_sub(1).ok_or(ValueStackUnderflow)?;
let index = *self.values.get(top_ix).ok_or(ValueStackUnderflow)? as usize;
let element_ix = top_ix.checked_sub(index).ok_or(ValueStackUnderflow)?;
let new_top_ix = top_ix.checked_sub(1).ok_or(ValueStackUnderflow)?;
let value = self.values[element_ix];
self.values
.copy_within(element_ix + 1..self.len, element_ix);
self.values[top_ix - 1] = value;
self.values[new_top_ix] = value;
self.len -= 1;
Ok(())
}
Expand Down Expand Up @@ -346,4 +347,13 @@ mod tests {
stack.apply_binary(|a, b| Ok(a / b)).unwrap();
assert_eq!(stack.peek(), Some(0));
}

// Subtract with overflow when stack size is 1 and element index is 0
// https://oss-fuzz.com/testcase-detail/5765856825507840
#[test]
fn move_index_avoid_overflow() {
let mut stack = make_stack!(&mut [0]);
// Don't panic
let _ = stack.move_index();
}
}
Loading