Skip to content

Commit

Permalink
Add assertions to avoid overflow t happen when subtracting from an un…
Browse files Browse the repository at this point in the history
…signed index
  • Loading branch information
alerque committed Nov 9, 2024
1 parent 7d6b730 commit 86f235c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/hb/ot_layout_gsubgpos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ pub fn match_lookahead(
start_index: usize,
end_index: &mut usize,
) -> bool {
// Function should always be called with a non-zero starting index
// c.f. https://github.com/harfbuzz/rustybuzz/issues/142
assert!(start_index >= 1);
let mut iter = skipping_iterator_t::new(ctx, start_index - 1, true);
iter.set_glyph_data(0);
iter.enable_matching(match_func);
Expand Down Expand Up @@ -1316,6 +1319,8 @@ pub fn ligate_input(
if this_comp == 0 {
this_comp = last_num_comps;
}
// c.f. https://github.com/harfbuzz/rustybuzz/issues/142
assert!(comps_so_far >= last_num_comps);
let new_lig_comp = comps_so_far - last_num_comps + this_comp.min(last_num_comps);
_hb_glyph_info_set_lig_props_for_mark(cur, lig_id, new_lig_comp);
}
Expand Down Expand Up @@ -1344,6 +1349,8 @@ pub fn ligate_input(
break;
}

// c.f. https://github.com/harfbuzz/rustybuzz/issues/142
assert!(comps_so_far >= last_num_comps);
let new_lig_comp = comps_so_far - last_num_comps + this_comp.min(last_num_comps);
_hb_glyph_info_set_lig_props_for_mark(info, lig_id, new_lig_comp)
}
Expand Down

0 comments on commit 86f235c

Please sign in to comment.