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 11, 2024
1 parent 7d6b730 commit 37e79ca
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 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 @@ -977,6 +980,7 @@ fn apply_lookup(
}
}

assert!(end >= 0);
ctx.buffer.move_to(end as usize);
}

Expand Down Expand Up @@ -1316,6 +1320,9 @@ pub fn ligate_input(
if this_comp == 0 {
this_comp = last_num_comps;
}
// Avoid the potential for a wrap-around bug when subtracting from an unsigned integer
// 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 +1351,9 @@ pub fn ligate_input(
break;
}

// Avoid the potential for a wrap-around bug when subtracting from an unsigned integer
// 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 37e79ca

Please sign in to comment.