* [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>
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.
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.
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
_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>
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>
Add AdobeVFPrototype_vsindex.otf (already used by test/api): two
VarData subtables with distinct region sets and a charstring-level
vsindex, covering VarData pruning/renumbering, vsindex remapping and
the re-emitted charstring prefix.
- Dissolve private-dict blends of VarDatas unused by any retained
charstring: under retain-gids, fdmap keeps FDs of hole glyphs the
usage pass never scanned, and their dicts were rewritten against a
dead transform.
- Take the partial path even when the store has regions but no
VarData subtables; the verbatim-copy fallback emitted a region list
whose axisCount contradicted the subsetted fvar (OTS-rejected).
- Make the usage pass honor drop-hints, so VarDatas referenced only by
hint blends don't survive as bloat.
- Require an actual instancing request for the pinned path: a face
without fvar plus a reused subset input made all_axes_pinned
spuriously true.
- Error-compensate the fold rounding across private-dict operators:
most blended dict values are delta-encoded, so independently rounded
folds accumulated in the decoded absolutes (blue zones drifted by
~0.5 per element); now every absolute is within 0.5 of exact.
- Clarify HB_SUBSET_FLAGS_DOWNGRADE_CFF2 doc: it applies to fully
pinned instancing.
Expected test outputs regenerated for the private-dict rounding
change.
Range limiting, pin-one-keep-one, a moved default, and axis dropping,
on AdobeVFPrototype. Expected outputs are hb-subset's own (fontTools
TTX comparison does not apply to CFF2 charstring encodings); they were
verified geometrically against both the original font and fontTools
varLib.instancer output at a grid of locations in the kept ranges.
Clip mask extents can have extreme signed origins after malformed
or heavily transformed outlines. Subtracting the surface origin in
int overflowed for cases such as 0 - INT_MIN.
Keep the mask-to-surface coordinate conversion in int64_t until
after intersecting with the finite clip and surface bounds, then
convert to unsigned only for proven in-range pixels.
Add the minimized OSS-Fuzz seed to the raster fuzzer corpus.
Testing: meson test -C build
Fixes: https://oss-fuzz.com/testcase-detail/4621471331450880
Assisted-by: OpenAI Codex <codex@openai.com>
From the spec: The value c is the character code in question, and i is the segment index in which c appears. If the value obtained from the indexing operation is not 0 (which indicates missingGlyph), idDelta[i] is added to it to get the glyph index. The idDelta arithmetic is modulo 65536.
get_base_glyph_paintrecord() looked up the BaseGlyphList with the
reference-returning bsearch(), which yields the all-zero Null object
when the glyph is absent, and then rejected non-matches by comparing
record->glyphId against the requested gid. For glyph 0 the Null
object's glyphId (0) equals the requested gid, so the sentinel was
taken for a real record. .notdef then resolved to a bogus empty paint,
and COLR::get_extents() returned success with 0,0,0,0 instead of
letting hb_ot_get_glyph_extents() fall back to the glyf outline.
Use bfind(), which reports presence directly, so a missing glyph
(including glyph 0) returns nullptr and extents fall back correctly.
This surfaced as a mark-positioning difference: fallback mark
positioning centers a mark using the base and mark glyph extents, so a
.notdef mark over a space was positioned differently from shapers that
report the real outline extents (e.g. fontations/HarfRust).
Testing:
- test/api/test-extents.c: glyph 0 (.notdef, has an outline) now
reports its outline extents; updated the expectation accordingly.
- b/util/hb-shape Noto-COLRv1.ttf -u 0020,0650 now matches
--font-funcs=fontations.
- meson test -C build (246 passed, 1 skipped)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Wire the HarfRust shaper through the active hb_font_t callback
surface so custom hb_font_funcs_t are respected during shaping.
Add a harfrust-specific test-shape invocation to cover that path.
Tested: meson test -C build test-shape-harfrust
Tested: HB_SHAPER_LIST=harfrust meson test -C build harfbuzz:shape_threads
Tested: HB_SHAPER_LIST=harfrust meson test -C build test-shape
Assisted-by: OpenAI Codex
---------
Co-authored-by: Chad Brokaw <cbrokaw@gmail.com>
Round COLRv1 alpha values when packing them into 8-bit colors in the
native OpenType and FreeType paint paths.
This removes the old downward truncation bias and aligns native output
with the backend behavior expected by the updated paint fixtures.
Update the affected test-paint fixtures for the rounded alpha values.
Testing:
CCACHE_DISABLE=1 meson test -C build --print-errorlogs
Assisted-by: OpenAI Codex
Reduce linear gradient anchors and normalize color lines before
printing them in test-paint. This makes the transcript reflect the
renderer-facing gradient geometry instead of backend-specific raw
COLRv1 anchors and stop ranges.
Also normalize signed zero in transform output so the fixtures stay
stable across backends.
Testing:
CCACHE_DISABLE=1 meson test -C build test-paint --print-errorlogs
Assisted-by: OpenAI Codex
Make the native COLRv1 paint paths report the root clip in font
units under the font transform. This matches the order used by
fontations and removes the need to pre-scale the HB-OT clip extents.
For the FreeType path, add a helper to convert FT_ClipBox values
back to font units before pushing them under the font transform, and
share that conversion with nested COLR glyph clip boxes.
Update paint and vector expectations for the new transform/clip stack.
Testing:
CCACHE_DISABLE=1 meson test -C build --print-errorlogs
Assisted-by: OpenAI Codex
The disabled assertions cover behavior from an older beyond-64k proposal.
That proposal has since changed, and current backends should not be
required to implement the stale loca-derived glyph count and metrics rules.
Keep the checks visible as disabled reminders until the library code is
adapted to the updated design.
Tested with:
CCACHE_DISABLE=1 HB_FONT_FUNCS=fontations meson test -C build test-be-glyph-advance test-be-num-glyphs
Assisted-by: OpenAI Codex
Correct the ArabicPUATraditional.txt entry for 0xF295 which should be
isolated not final form. Also enable 0xFC43 ligature so the ligature is
actually used.
Fixes https://github.com/harfbuzz/harfbuzz/issues/5984
Add focused API tests for hb_buffer_create_similar() and buffer
configuration persistence across clear/reset. Also exercise public hb_map
copy, equality, hash, update, iteration, keys, and values paths with
order-independent assertions.
Validation:
meson test -C build-tgl-precheck --print-errorlogs --suite api test-buffer
meson test -C build-tgl-precheck --print-errorlogs --suite api test-map
meson test -C build-tgl-precheck --print-errorlogs --suite api test-buffer test-map
Assisted-by: OpenAI Codex <codex@openai.com>
Co-authored-by: jeffhuang <jeff@docker.xydrsucermoubd24xgo33yhsgd.bx.internal.cloudapp.net>
* [fontations] Fix OOB write on glyph-name callback with size == 0
The Rust `_hb_fontations_glyph_name()` callback computed
`glyph_name.len().min(size as usize - 1)`. When a caller passed
`size == 0`, `size as usize - 1` underflowed a `usize` to
`usize::MAX`, the `min()` clamp collapsed to `glyph_name.len()`,
and the subsequent `copy_nonoverlapping` / trailing NUL wrote
`glyph_name.len() + 1` bytes into a zero-capacity caller buffer.
This is an out-of-bounds write reachable from the public API
whenever the build was configured with `-Dfontations=enabled`
and the application had called `hb_fontations_font_set_funcs()`.
Short-circuit the `size == 0` case before the subtraction.
Return `true` in that case to match the existing post and CFF1
backends (`hb-ot-post-table.hh`, `hb-ot-cff1-table.hh`), which
both early-out with `return true` on `!buf_len` — the glyph
does have a name; we simply had no buffer to write it into.
Regression tests added in `test/api/test-glyph-names.c` cover
the zero-size path on post and CFF1 backends, a sub-font, a
NULL buffer, and `size == 1` / small-buffer / exact-fit cases
so the truncation path does not silently regress.
Fixes: https://github.com/harfbuzz/harfbuzz/issues/5946
Assisted-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* [font] Reject glyph-name lookups with size == 0 at the wrapper
`hb_font_t::get_glyph_name()` previously pre-wrote the trailing
NUL only when `size != 0` but still dispatched to the backend
callback with `size == 0`. Every current glyph-name backend has
to re-validate that argument: `post` and `cff1` short-circuit
with `return true`, the new Rust `fontations` callback now
short-circuits too (prior commit), and the CoreText callback in
`hb-coretext-font.cc` has a structurally similar `(CFIndex)size
- 1` pattern.
Normalize this at the wrapper layer: return `false` immediately
on `size == 0`, before any backend dispatch and before the
`*name = '\0'` write. This makes the zero-size case a single,
auditable no-op for every glyph-name provider (native or Rust,
current or future) and removes the CoreText underflow from the
reachable surface through the same chokepoint.
Observable change: callers that invoked
`hb_font_get_glyph_name(font, gid, buf, 0)` on post/cff1 backed
fonts used to get `true` back; they now get `false`. `size == 0`
queries carry no useful information for the caller, so this is
considered a safe hardening rather than a contract break.
Assisted-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* [font] Preserve glyph-name zero-size probe semantics
Keep `hb_font_get_glyph_name(..., NULL, 0)` as a valid
return-value-only probe instead of rejecting `size == 0` in the
wrapper.
Fix the remaining backend-specific zero-size paths in hb-ft and
hb-coretext-font so they answer the probe without dereferencing the
caller buffer, and update the API tests to assert the preserved
behavior.
Testing: CCACHE_DISABLE=1 meson test -C build test-glyph-names
Testing: CCACHE_DISABLE=1 meson test -C build test-ft
Assisted-by: OpenAI Codex <codex@openai.com>
---------
Co-authored-by: jeffhuang <jeff@docker.xydrsucermoubd24xgo33yhsgd.bx.internal.cloudapp.net>