Skip to content

Commit

Permalink
Track HarfBuzz's signed/unsigned integer types to avoid overflows
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Nov 9, 2024
1 parent 7386be4 commit e4a4eac
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/hb/ot_layout_gsubgpos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ fn apply_lookup(

// All positions are distance from beginning of *output* buffer.
// Adjust.
let mut end = {
let mut end: isize = {
let backtrack_len = ctx.buffer.backtrack_len();
let delta = backtrack_len as isize - ctx.buffer.idx as isize;

Expand All @@ -867,7 +867,7 @@ fn apply_lookup(
match_positions[j] = (match_positions[j] as isize + delta) as _;
}

backtrack_len + match_end - ctx.buffer.idx
backtrack_len as isize + match_end as isize - ctx.buffer.idx as isize
};

for record in lookups {
Expand Down Expand Up @@ -928,8 +928,8 @@ fn apply_lookup(
//
// It should be possible to construct tests for both of these cases.

end = end.saturating_add_signed(delta);
if end < match_positions[idx] {
end += delta;
if end < match_positions[idx] as isize {
// End might end up being smaller than match_positions[idx] if the recursed
// lookup ended up removing many items.
// Just never rewind end beyond start of current position, since that is
Expand All @@ -939,7 +939,7 @@ fn apply_lookup(
// https://github.com/harfbuzz/harfbuzz/issues/1611
//
delta += match_positions[idx] as isize - end as isize;
end = match_positions[idx];
end = match_positions[idx] as isize;
}

// next now is the position after the recursed lookup.
Expand Down Expand Up @@ -977,7 +977,7 @@ fn apply_lookup(
}
}

ctx.buffer.move_to(end);
ctx.buffer.move_to(end as usize);
}

/// Value represents glyph class.
Expand Down

0 comments on commit e4a4eac

Please sign in to comment.