Skip to content

Commit 47af6da

Browse files
committed
Track HarfBuzz's signed/unsigned integer types to avoid overflows
1 parent 7386be4 commit 47af6da

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/hb/ot_layout_gsubgpos.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,9 @@ impl<'a, 'b> skipping_iterator_t<'a, 'b> {
312312
}
313313

314314
pub fn prev(&mut self, unsafe_from: Option<&mut usize>) -> bool {
315-
let stop = 0;
315+
let stop: usize = 0;
316316

317-
while self.buf_idx > stop as usize {
317+
while self.buf_idx > stop {
318318
self.buf_idx -= 1;
319319
let info = &self.ctx.buffer.out_info()[self.buf_idx];
320320

@@ -858,7 +858,7 @@ fn apply_lookup(
858858

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

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

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

873873
for record in lookups {
@@ -928,8 +928,8 @@ fn apply_lookup(
928928
//
929929
// It should be possible to construct tests for both of these cases.
930930

931-
end = end.saturating_add_signed(delta);
932-
if end < match_positions[idx] {
931+
end += delta;
932+
if end < match_positions[idx] as isize {
933933
// End might end up being smaller than match_positions[idx] if the recursed
934934
// lookup ended up removing many items.
935935
// Just never rewind end beyond start of current position, since that is
@@ -938,8 +938,8 @@ fn apply_lookup(
938938
// https://bugs.chromium.org/p/chromium/issues/detail?id=659496
939939
// https://github.com/harfbuzz/harfbuzz/issues/1611
940940
//
941-
delta += match_positions[idx] as isize - end as isize;
942-
end = match_positions[idx];
941+
delta += match_positions[idx] as isize - end;
942+
end = match_positions[idx] as isize;
943943
}
944944

945945
// next now is the position after the recursed lookup.
@@ -977,7 +977,7 @@ fn apply_lookup(
977977
}
978978
}
979979

980-
ctx.buffer.move_to(end);
980+
ctx.buffer.move_to(end as usize);
981981
}
982982

983983
/// Value represents glyph class.

0 commit comments

Comments
 (0)