Skip to content

Commit

Permalink
Avoid possible integer overflows computing indexes in OT layout
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Nov 9, 2024
1 parent 7386be4 commit 424d79f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/hb/ot_layout_gsubgpos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ pub fn match_lookahead(
start_index: usize,
end_index: &mut usize,
) -> bool {
let mut iter = skipping_iterator_t::new(ctx, start_index - 1, true);
let mut iter = skipping_iterator_t::new(ctx, start_index.saturating_sub(1), true);
iter.set_glyph_data(0);
iter.enable_matching(match_func);

Expand Down Expand Up @@ -867,7 +867,9 @@ fn apply_lookup(
match_positions[j] = (match_positions[j] as isize + delta) as _;
}

backtrack_len + match_end - ctx.buffer.idx
backtrack_len
.saturating_add(match_end)
.saturating_sub(ctx.buffer.idx)
};

for record in lookups {
Expand Down Expand Up @@ -1316,7 +1318,9 @@ pub fn ligate_input(
if this_comp == 0 {
this_comp = last_num_comps;
}
let new_lig_comp = comps_so_far - last_num_comps + this_comp.min(last_num_comps);
let new_lig_comp = comps_so_far
.saturating_add(this_comp.min(last_num_comps))
.saturating_sub(last_num_comps);
_hb_glyph_info_set_lig_props_for_mark(cur, lig_id, new_lig_comp);
}
buffer.next_glyph();
Expand Down Expand Up @@ -1344,7 +1348,9 @@ pub fn ligate_input(
break;
}

let new_lig_comp = comps_so_far - last_num_comps + this_comp.min(last_num_comps);
let new_lig_comp = comps_so_far
.saturating_add(this_comp.min(last_num_comps))
.saturating_sub(last_num_comps);
_hb_glyph_info_set_lig_props_for_mark(info, lig_id, new_lig_comp)
}
}
Expand Down

0 comments on commit 424d79f

Please sign in to comment.