mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-20 06:21:16 +01:00
get_advance_with_var_unscaled adds the HVAR/VVAR advance delta to the base advance and returns the sum as unsigned. The delta from ItemVariationStore::get_delta is an unbounded float, so an HVAR whose item-variation store uses long-word (int32) deltas across several regions that all peak at the axis extreme can make advance + roundf (delta) exceed the unsigned range; converting that float to unsigned is then undefined behavior (UBSan float-cast-overflow), and hb_max (0.0f, NaN) would likewise pass NaN to the conversion. Reached from the public hb_font_get_glyph_h_advance / v_advance on a variable font. Clamp the accumulated value into the unsigned range with hb_clamp_to before returning, matching the saturation already used for the variation-derived glyph-extents arithmetic. Valid advances are unchanged. The template is shared by hmtx/HVAR and vmtx/VVAR, so all three advance sites are covered. Add a regression test under test/api driving a crafted long-word HVAR; it reports float-cast-overflow under the sanitizers job without the fix and passes with it. The full meson test suite passes.