Skip to content

Commit 424d79f

Browse files
committed
Avoid possible integer overflows computing indexes in OT layout
1 parent 7386be4 commit 424d79f

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/hb/ot_layout_gsubgpos.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ pub fn match_lookahead(
170170
start_index: usize,
171171
end_index: &mut usize,
172172
) -> bool {
173-
let mut iter = skipping_iterator_t::new(ctx, start_index - 1, true);
173+
let mut iter = skipping_iterator_t::new(ctx, start_index.saturating_sub(1), true);
174174
iter.set_glyph_data(0);
175175
iter.enable_matching(match_func);
176176

@@ -867,7 +867,9 @@ 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
871+
.saturating_add(match_end)
872+
.saturating_sub(ctx.buffer.idx)
871873
};
872874

873875
for record in lookups {
@@ -1316,7 +1318,9 @@ pub fn ligate_input(
13161318
if this_comp == 0 {
13171319
this_comp = last_num_comps;
13181320
}
1319-
let new_lig_comp = comps_so_far - last_num_comps + this_comp.min(last_num_comps);
1321+
let new_lig_comp = comps_so_far
1322+
.saturating_add(this_comp.min(last_num_comps))
1323+
.saturating_sub(last_num_comps);
13201324
_hb_glyph_info_set_lig_props_for_mark(cur, lig_id, new_lig_comp);
13211325
}
13221326
buffer.next_glyph();
@@ -1344,7 +1348,9 @@ pub fn ligate_input(
13441348
break;
13451349
}
13461350

1347-
let new_lig_comp = comps_so_far - last_num_comps + this_comp.min(last_num_comps);
1351+
let new_lig_comp = comps_so_far
1352+
.saturating_add(this_comp.min(last_num_comps))
1353+
.saturating_sub(last_num_comps);
13481354
_hb_glyph_info_set_lig_props_for_mark(info, lig_id, new_lig_comp)
13491355
}
13501356
}

0 commit comments

Comments
 (0)