* [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>
Several public "list getter" APIs document their output array as nullable
(pass NULL to just query the total count without storing anything), but
their implementations gated the copy only on the count pointer:
if (count)
{
+ source.sub_array (start_offset, count)
| hb_sink (hb_array (out, *count)); // writes through out even if NULL
}
Passing a non-NULL count with a NULL output array on a populated table
therefore wrote through the NULL pointer and crashed (SIGSEGV).
Gate each copy on the output pointer as well (the same idiom already used
by hb_color_line_get_color_stops: "if (count && out)"). This is a no-op
when the output array is non-NULL and restores the documented behaviour of
returning the total count when it is NULL. Affected getters:
- hb_ot_color_palette_get_colors (CPAL)
- hb_ot_color_glyph_get_layers (COLR v0)
- hb_ot_meta_get_entry_tags (meta)
- hb_aat_layout_get_feature_types (AAT feat)
- hb_aat_layout_feature_type_get_selector_infos (AAT feat)
- hb_ot_layout_feature_get_characters (GSUB cvXX)
- hb_ot_layout_lookup_get_glyph_alternates (GSUB aalt)
Add test/api/test-ot-nullable-output.c exercising each route with a NULL
output array; every case crashed before this change.
Fixes: GHSA-v5mv-8hhw-vff8
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
hb_pdf_build_indexed_smask() computed its buffer sizes with unchecked
32-bit arithmetic:
unsigned raw_len = (width + 1) * height;
...
out->resize (width * height);
width/height come straight from the attacker-controlled PNG IHDR (the
vector-PDF path re-parses IHDR itself and does not clamp dimensions,
unlike sbix). For width = height = 65536, (width + 1) * height wraps to
65536 and width * height wraps to 0. A crafted IDAT inflating to the
wrapped raw_len passes the length check, the mask buffer is resized to
zero, and the per-pixel loop then writes through out->arrayZ[y*width+x]
and reads past raw -- an out-of-bounds write / NULL-page store and crash.
Reject zero/degenerate dimensions and use hb_unsigned_mul_overflows()
for both (width + 1) * height and width * height before allocating,
sizing the inflate, and indexing. This bounds every subsequent
raw + y*(width+1) and out->arrayZ[y*width+x] access.
Add a CBDT regression seed embedding a 65536x65536 indexed PNG with a
tRNS chunk; it reaches the soft-mask builder through
hb_font_paint_glyph -> CBDT::paint_glyph -> hb_pdf_paint_image and
crashed pre-fix under ASAN/UBSan at hb-vector-paint-pdf.cc:617.
Fixes: GHSA-gmjm-qc3c-qfp8
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The PNG chunk-bounds check in hb_pdf_paint_image() used wrapping
32-bit unsigned arithmetic:
if (pos + 12 + chunk_len > len)
break;
A large attacker-controlled chunk_len (e.g. 0xFFFFFF30) wraps
pos + 12 + chunk_len below len, so a truncated PLTE chunk passes the
check. The oversized plte_len is then trusted during palette
serialization in add_xobject_png_image(), reading far past the input
buffer -- an out-of-bounds read and deterministic crash.
Rewrite the bounds checks to be non-wrapping, relying on the invariant
pos <= len (len >= 8 is checked earlier): gate the loop on
len - pos >= 12 and reject a chunk with chunk_len > len - pos - 12.
This keeps pos <= len across pos += 12 + chunk_len and makes every
in-loop read (chunk header and chunk payload) provably in bounds.
Add a regression seed font that embeds a malformed indexed PNG with an
oversized PLTE length via sbix. It reaches the vector-PDF paint path
through hb_font_paint_glyph -> sbix::paint_glyph -> hb_pdf_paint_image
and crashed pre-fix under ASAN at hb-vector-paint-pdf.cc:222; it now
renders cleanly.
Fixes: GHSA-9m78-3jcg-57f2
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Meson does not version shared libraries on Android, so the generic unix case for generating harfbuzz-config.cmake results in a broken cmake config module.
Assisted-by: OpenCode
Reviewed-by: hlewin@worldiety.de
Tested-by: hlewin@worldiety.de