Skip to content

Commit d5b704b

Browse files
committed
Add assertions to avoid overflow t happen when subtracting from an unsigned index
1 parent 47af6da commit d5b704b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/hb/ot_layout_gsubgpos.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ pub fn match_lookahead(
170170
start_index: usize,
171171
end_index: &mut usize,
172172
) -> bool {
173+
// Function should always be called with a non-zero starting index
174+
// c.f. https://github.com/harfbuzz/rustybuzz/issues/142
175+
assert!(start_index >= 1);
173176
let mut iter = skipping_iterator_t::new(ctx, start_index - 1, true);
174177
iter.set_glyph_data(0);
175178
iter.enable_matching(match_func);
@@ -977,7 +980,7 @@ fn apply_lookup(
977980
}
978981
}
979982

980-
ctx.buffer.move_to(end as usize);
983+
ctx.buffer.move_to(end.try_into().unwrap());
981984
}
982985

983986
/// Value represents glyph class.
@@ -1316,6 +1319,9 @@ pub fn ligate_input(
13161319
if this_comp == 0 {
13171320
this_comp = last_num_comps;
13181321
}
1322+
// Avoid the potential for a wrap-around bug when subtracting from an unsigned integer
1323+
// c.f. https://github.com/harfbuzz/rustybuzz/issues/142
1324+
assert!(comps_so_far >= last_num_comps);
13191325
let new_lig_comp = comps_so_far - last_num_comps + this_comp.min(last_num_comps);
13201326
_hb_glyph_info_set_lig_props_for_mark(cur, lig_id, new_lig_comp);
13211327
}
@@ -1344,6 +1350,9 @@ pub fn ligate_input(
13441350
break;
13451351
}
13461352

1353+
// Avoid the potential for a wrap-around bug when subtracting from an unsigned integer
1354+
// c.f. https://github.com/harfbuzz/rustybuzz/issues/142
1355+
assert!(comps_so_far >= last_num_comps);
13471356
let new_lig_comp = comps_so_far - last_num_comps + this_comp.min(last_num_comps);
13481357
_hb_glyph_info_set_lig_props_for_mark(info, lig_id, new_lig_comp)
13491358
}

0 commit comments

Comments
 (0)