Skip to content

Commit e4a4eac

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

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/hb/ot_layout_gsubgpos.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -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
@@ -939,7 +939,7 @@ fn apply_lookup(
939939
// https://github.com/harfbuzz/harfbuzz/issues/1611
940940
//
941941
delta += match_positions[idx] as isize - end as isize;
942-
end = match_positions[idx];
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)