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
Fill the glyph shape directly. This simplifies the SVG/PDF output and
fixes the SVG clipping issue with COLRv0 layers and large scale, as
there is no clip now at all.
Instead of painting COLRv0 and outline fallback layers with
push_clip_glyph + color + pop_clip, add a dedicated callback for this
common paint operation.
The default (*_nil) implementation uses the decomposed sequence, so
existing clients without a fill_glyph implementation continue to work as
before.
The fallback quadratic-to-cubic promotion works in single precision.
This results in different rounding values for different architectures.
Promote in double precision instead, which rounds deterministically.
Add a PDF test that exercises this, and make the test runner handle PDF
expectations.
This also effectively reverts d4511648db
The list-getter APIs accept a NULL output array to query just the total
count (and, since the preceding commits, do so safely). Annotate the
output-array parameters (nullable) in the gtk-doc blocks so introspection
bindings reflect that contract, matching the already-nullable CPAL/COLR
getters.
Covers hb_ot_meta_get_entry_tags, hb_aat_layout_get_feature_types,
hb_ot_layout_feature_get_characters, hb_ot_layout_lookup_get_glyph_alternates,
hb_ot_layout_get_attach_points, hb_ot_layout_get_ligature_carets,
hb_ot_layout_table_get_script_tags / _get_feature_tags / _get_language_tags,
hb_ot_layout_language_get_feature_indexes / _get_feature_tags,
hb_ot_layout_feature_get_lookups / _with_variations_get_lookups,
hb_ot_math_get_glyph_kernings / _assembly / _variants,
hb_ot_var_get_axes / _get_axis_infos / _named_instance_get_design_coords,
and hb_face_get_table_tags.
Assisted-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
_hb_ft_get_table_tags() (used for FT faces created over a custom stream,
i.e. when ft_face->stream->read is set) did
if (!table_count) return population;
else *table_count = 0;
...
end_offset = hb_min (start_offset + *table_count, population);
zeroing *table_count before using it as the requested buffer size, so
end_offset collapsed to start_offset, the copy loop never ran, and
hb_face_get_table_tags() always reported zero tags (and wrote none).
Restructure to match the CoreText / face-builder / default backends: keep
the caller's *table_count, check the start_offset + *table_count sum for
overflow, clamp to the table population, then copy. Also guard the copy
on table_tags so a NULL output array (count-only query) is handled.
The existing FT test used FT_New_Memory_Face, whose in-memory face routes
through the default blob table-tags path and never exercised this
callback. Add a streaming-face variant (FT_Open_Face with a read stream)
that does; it failed (count 0 vs 3) before this fix.
Assisted-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Following GHSA-v5mv-8hhw-vff8, sweep the rest of the public "list getter"
APIs for the same defect: a NULL output array passed with a non-NULL count
on a populated table wrote through the NULL pointer and crashed (SIGSEGV).
These output params are not all annotated nullable, but the crash is
reachable from public C APIs and is a straightforward DoS, so guard the
write on the output pointer consistently (matching hb_color_line_get_color_stops
and the fixes in the previous two commits). When the output is NULL the
getter now just returns the total count.
Getters hardened:
- MathKern::get_entries (hb_ot_math_get_glyph_kernings)
- MathGlyphAssembly::get_parts (hb_ot_math_get_glyph_assembly)
- MathGlyphConstruction::get_variants (hb_ot_math_get_glyph_variants)
- IndexArray::get_indexes (hb_ot_layout_language_get_feature_indexes,
hb_ot_layout_feature_get_lookups, ...)
- RecordListOf::get_tags (hb_ot_layout_table_get_script_tags,
_get_feature_tags, _get_language_tags, ...)
- AttachList::get_attach_points (hb_ot_layout_get_attach_points)
- LigGlyph::get_lig_carets (hb_ot_layout_get_ligature_carets)
- fvar get_axis_infos / get_axes_deprecated / get_instance_coords
(hb_ot_var_get_axis_infos, hb_ot_var_get_axes,
hb_ot_var_named_instance_get_design_coords)
- OpenTypeOffsetTable / CoreText / face-builder get_table_tags
(hb_face_get_table_tags)
Extend test/api/test-ot-nullable-output.c with table-tags, fvar axis-info
and MATH kerning cases; each crashed before this change.
Assisted-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
hb_ot_layout_lookup_get_glyph_alternates() documents its alternate_glyphs
output as nullable, and the AlternateSubst path was fixed in the previous
commit. The Single-substitution fallback paths (SingleSubstFormat1 and
SingleSubstFormat2, used when the queried lookup is a single-substitution)
had the same defect: they gated the write on
if (alternate_count && *alternate_count)
and then did *alternate_glyphs = glyph_id without checking alternate_glyphs.
Passing a NULL alternate_glyphs with a non-NULL, non-zero count on a covered
glyph therefore wrote through NULL and crashed.
Also require alternate_glyphs to be non-NULL before storing.
Fixes: GHSA-v5mv-8hhw-vff8
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
hb_vector_buf_t::append_base64() sized its output as
unsigned out_len = ((len + 2) / 3) * 4;
which overflows 32-bit for a very large len (len + 2 wraps, and the * 4
wraps for len above ~3.2 GB). len is the attacker-controlled embedded
PNG length on the vector SVG paint path (hb-vector-paint-svg.cc), so a
wrapped out_len under-sizes the buffer while the encode loop still writes
4 bytes per 3 input bytes -- a heap out-of-bounds write.
Compute the group count without the +2 (len / 3 + (len % 3 != 0)) and use
hb_unsigned_mul_overflows()/hb_unsigned_add_overflows() so an oversized
input fails the allocation instead of wrapping. resize_full() already
rejects a size that does not fit in int, so the remaining path is safe.
Assisted-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>