From b7898a94cf339d878a24bf9c5fd07faf802c09be Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 9 Nov 2024 15:13:26 +0300 Subject: [PATCH] Add assertions to avoid overflow t happen when subtracting from an unsigned index --- src/hb/ot_layout_gsubgpos.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/hb/ot_layout_gsubgpos.rs b/src/hb/ot_layout_gsubgpos.rs index 45011f04..06d13c12 100644 --- a/src/hb/ot_layout_gsubgpos.rs +++ b/src/hb/ot_layout_gsubgpos.rs @@ -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); @@ -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); } @@ -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) }