* [instancer] Don't dedup VarStore rows when not optimizing
as_item_varstore dropped duplicate delta rows even with optimize=false,
where varidx_map is left empty and callers rely on original
VariationIndex values staying valid. HVAR/VVAR subsetting uses that
mode when the source table has an implicit (map-less) advance mapping:
any two glyphs sharing identical deltas shifted every following row, so
the synthesized identity map pointed at wrong rows and past the end of
the VarData — advances silently froze or took neighbors' deltas when
partially instancing such fonts (e.g. Source Han fonts).
Fixes https://github.com/harfbuzz/harfbuzz/issues/6068
* [subset] Drop identity advance maps for map-less HVAR/VVAR sources
When the source table uses implicit glyph-id indexing, the subsetter
synthesized an advance DeltaSetIndexMap whose content was the identity
over every output glyph — equivalent to the implicit indexing it
replaced, just bigger. Recognize that case in is_identity () and keep
the output map-less, like fontTools does. Sources that carry a real
map keep one, preserving their form; truncated maps don't qualify since
glyphs past their end share the last value.
retain-num-glyphs expected files regenerated: NotoSansJP-VF.subset.otf
is map-less, and its redundant identity map is now dropped (verified
against fontTools output).
* [test/subset] Test partial instancing of map-less HVAR
ImplicitHVAR.ttf carries an HVAR with implicit (map-less) advance
indexing and deliberately duplicated delta rows, the combination that
broke before the row-dedup fix: rows shifted or fell off the end of the
rebuilt VarData and advances silently froze. Expected outputs are
cross-checked against fontTools varLib.instancer + subset.
* [raster] clamp coordinates before converting to int
the transformed glyph extents and the flattened segment endpoints are floats derived from int32 inputs and can land far outside the int range, so the conversions were undefined and the extent subtraction overflowed on top of that. saturate through a shared helper and widen the subtraction.
* [raster] generalize int32 saturating cast into hb_clamp_to<>
Move the raster-local hb_raster_clamp_to_int32 helper into hb-algs.hh
as a generic hb_clamp_to<T> that saturates a floating-point value to
the range of any integer type, and use hb_clamp_to<int32_t> at the
three raster call sites.
Signed-off-by: nussaiba shaikh <nussaibah@bugqore.com>
---------
Signed-off-by: nussaiba shaikh <nussaibah@bugqore.com>
Add internal ALWAYS_INLINE helpers hb_malloc2(nmemb, size) and
hb_realloc2(ptr, nmemb, size) in hb-algs.hh that check for
multiplication overflow before calling hb_malloc/hb_realloc.
Convert call sites that had unchecked n * sizeof(T) multiplications:
- src/OT/glyf/glyf-helpers.hh
- src/hb-cairo-utils.cc
- src/hb-gpu-paint.cc
- src/hb-map.hh
- src/hb-ot-post-table.hh
- src/hb-shape.cc
Also fix raw malloc/free in src/main.cc to use hb_malloc/hb_free.
hb_buffer_deserialize_unicode() and hb_buffer_deserialize_glyphs() each
mutated the buffer's content_type unconditionally before checking
whether the caller-supplied format was recognized, then returned false
without rolling that back for an invalid format. A buffer left with
content_type set but len == 0 fails the assert_glyphs() /
assert_unicode() invariant on a later, independent call that expects
a clean buffer, aborting the process:
- deserialize_unicode(INVALID) -> deserialize_glyphs() aborts in
assert_glyphs().
- deserialize_glyphs(INVALID) -> add_codepoints() aborts in
assert_unicode().
Move each hb_buffer_set_content_type() call into the TEXT/JSON case
bodies of the existing format switch, instead of guarding it with a
separate validity check ahead of the switch. The switch's own case
list is already the single source of truth for which formats are
supported, so this avoids duplicating that knowledge in a second
condition that could drift out of sync with the switch.
Testing:
- Built with -Db_sanitize=address,undefined.
- Reproduced both original aborts against the unfixed code
(SIGABRT via assert_glyphs()/assert_unicode()).
- Rebuilt with the fix and reran both reproducers: clean exit, no
assertion failure.
- Ran the full test suite (meson test, sanitizer build, FreeType +
ICU enabled) before and after: 71/75 pass in both, with the same
4 pre-existing failures unrelated to buffer serialization
(check-libstdc++, and the experimental vector/raster/gpu-fuzzer
chunk 2 targets) - confirmed to fail identically on the
unmodified baseline, so no regressions from this change.
Assisted-by: Claude Sonnet 5 <noreply@anthropic.com>
hb_ot_tag_to_language returns NULL for HB_OT_TAG_DEFAULT_LANGUAGE, and hb_language_to_string returns NULL for it, so the script-suffix path called strlen on a NULL pointer whenever the primary script tag did not match the input. Skip the suffix construction when there is no base language string and leave the default (NULL) language in place.
Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
push_clip_path_end wrote clip_stack[clip_depth] without the
HB_GPU_PAINT_MAX_CLIP_DEPTH check that push_clip_glyph and
push_clip_path_start both apply. clip_depth can be pushed past
the fixed 3-entry clip_stack, so closing a clip path while the
stack is full writes a pending_clip_t past the array. Guard it
like the sibling clip pushes.
The range test guarding the bilinear sampler is comparison-based, so NaN
coordinates pass it and reach (int) floorf() in
hb_raster_sample_bilinear_premul, where only x1/y1 are clamped. The
determinant guard has the same shape, so a transform that overflows to
infinity is accepted and 1/inf turns inf * 0 into NaN.
* [subset-repack] fix potential out of bounds accesses
make sure we create a deep copy of the object before we mutate
* [subset-repack] fix is_shared(): only check real parents
* [subset-repack] add tests
* [subset-repack] apply AI proposed change
* address review comments
* [subset-repack] no need to duplicate shared liga_sets beforehand
Since we now would create a memory copy of the object before mutating
it, I think checking and duplicating shared liga_sets is not needed.
* [subset-repack] fix potential out of bounds accesses
make sure we create a deep copy of the object before we mutate
* [subset-repack] fix is_shared(): only check real parents
* [subset-repack] add tests
* [subset-repack] apply AI proposed change
* address review comments
* [subset-repack] no need to duplicate shared liga_sets beforehand
Since we now would create a memory copy of the object before mutating
it, I think checking and duplicating shared liga_sets is not needed.
The dispatch wrapper handed the callback user_data->push_clip_glyph
instead of user_data->color_glyph, so a client registering both
callbacks with different contexts got the wrong pointer on every
COLR glyph.
The vertical-origin cache stores scaled y-origin values, but it was
validated against serial_coords. Changing only the font scale leaves
serial_coords unchanged, so hb_font_set_scale() could keep serving stale
vertical origins.
Validate scale-dependent OT font caches against the full font serial and
check that serial before using the batched vertical-origin callback. Add
an API regression that changes y_scale on one font and verifies the
vertical origin is recomputed.
Testing:
meson compile -C build test/api/test-ot-face
meson test -C build test-ot-face --print-errorlogs
meson test -C build --suite api --print-errorlogs
Fixes: https://github.com/harfbuzz/harfbuzz/issues/6066
Assisted-by: OpenAI Codex
Detect the fill-glyph pattern in the COLRv1 graph: a PaintGlyph whose
child is a (Var)PaintSolid, and emit a single fill_glyph instead of
push_clip_glyph + color + pop_clip.
GLib removed G_GNUC_CONST from generated get_type declarations because
GType registration can initialize state and the attribute can cause
miscompilations with GCC trunk.
Match that behavior for generated GObject enum declarations.
Fixes: https://github.com/harfbuzz/harfbuzz/issues/6060
Assisted-by: OpenAI Codex