Skip to content

Commit 24fb1c8

Browse files
authored
[skrifa] tthint: adjust DELTAP/DELTAC limits (#1353)
We limited these to point count/cvt size respectively but there are fonts (Arial is one) where these limits are not sufficient. Notably, you can have one exception per point/entry _and_ ppem so we can't use these counts for hard limits. Instead limit both to `(stack_size / 2)` since each iteration requires two elements from the stack.
1 parent ad6e5a9 commit 24fb1c8

File tree

1 file changed

+8
-6
lines changed
  • skrifa/src/outline/glyf/hint/engine

1 file changed

+8
-6
lines changed

skrifa/src/outline/glyf/hint/engine/delta.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ impl Engine<'_> {
3232
let ppem = gs.ppem as u32;
3333
let point_count = gs.zp0().points.len();
3434
let n = self.value_stack.pop_count_checked()?;
35-
// Additionally limit n to the number of points in zp0 since
36-
// we don't expect to modify a point more than once
37-
let n = n.min(point_count);
35+
// Each exception requires two values on the stack so limit our
36+
// count to prevent looping in non-pedantic mode (where the stack ops
37+
// will produce 0 instead of an underflow error)
38+
let n = n.min(self.value_stack.len() / 2);
3839
let bias = match opcode {
3940
Opcode::DELTAP2 => 16,
4041
Opcode::DELTAP3 => 32,
@@ -98,9 +99,10 @@ impl Engine<'_> {
9899
let gs = &mut self.graphics;
99100
let ppem = gs.ppem as u32;
100101
let n = self.value_stack.pop_count_checked()?;
101-
// Additionally limit n to the number of CVT entries since we
102-
// don't expect to modify an entry more than once
103-
let n = n.min(self.cvt.len());
102+
// Each exception requires two values on the stack so limit our
103+
// count to prevent looping in non-pedantic mode (where the stack ops
104+
// will produce 0 instead of an underflow error)
105+
let n = n.min(self.value_stack.len() / 2);
104106
let bias = match opcode {
105107
Opcode::DELTAC2 => 16,
106108
Opcode::DELTAC3 => 32,

0 commit comments

Comments
 (0)