FreeType requires face creation and destruction on a shared
FT_Library to be serialized. Protect the lazily-created static library,
its reference count, and its internally-owned faces with a lazy mutex.
Keep caller-owned FT_Library instances outside the new lock, and add a
multithreaded regression test for blob-backed faces and font funcs.
Tests: meson test -C build (272/272 passed)
Fixes: https://github.com/harfbuzz/harfbuzz/issues/6224
Assisted-by: OpenAI Codex <codex@openai.com>
When the requested direction differs from the script's horizontal
direction, the Graphite2 shaper reverses the buffer before segmenting.
Input cluster values then decrease along the buffer, so assigning each
Graphite group the cluster of its base character can leave earlier
characters outside the resulting cluster map.
Preserve the source span of every Graphite glyph while constructing the
output. At monotone cluster levels, seed each glyph from the minimum
endpoint of that span and use merge_clusters() over each Graphite output
range. Keep the historical base-character behavior at non-monotone
levels.
HarfBuzz cluster values are opaque client labels and can be repeated or
gapped. Merging them can therefore coalesce multiple Graphite layout
groups. Preserve the Graphite group index separately for positioning so
every group's advance is emitted even when its HarfBuzz cluster was
merged. Validate Graphite slot source bounds before indexing the input.
Add shape regressions using a subset of Awami Nastaliq and an API test
with repeated input clusters. The latter used to merge the output
clusters correctly but drop an entire layout-group advance, reducing
the total from 3200 to 1269.
Tested with:
meson test -C build test-graphite2
meson test -C build --suite shape
meson test -C build
Assisted-by: Codex <codex@openai.com>
Co-authored-by: Michael Brown <michael.brown@rubicotech.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Expose the exact set-intersection query so callers can test whether two
sets have any elements in common without copying and mutating a set.
The implementation handles inverted sets through the internal helper.
Document the new API with its release placeholder, add it to the docs
section index, and cover regular and inverted set combinations.
Tested with the full Meson test suite (270/270 passed).
Assisted-by: OpenAI Codex <codex@openai.com>
The subset planner rejected out-of-range avar2 delta-set indices even
though runtime evaluation treats them as zero. The avar2 rewrite also
carried those invalid indices into its output mapping.
Validate delta-set indices centrally and normalize invalid mappings to
NO_VARIATION_INDEX during planning and rewriting. Add coverage for an
empty non-NULL VarStore with an implicit index map.
Tests: meson test -C build
Assisted-by: OpenAI Codex
Widen position differences before taking their absolute value. This
avoids signed overflow when hb_buffer_diff() compares positions near
opposite ends of the hb_position_t range.
Add an API regression covering INT32_MIN versus INT32_MAX.
Tested with: meson test -C build --print-errorlogs
Assisted-by: OpenAI Codex
Mark-to-mark attachment can accumulate an unbounded cross-direction
offset. Clamp anchor conversion and saturate the immediate addition so
overlong mark clusters stop at hb_position_t limits instead of invoking
signed-overflow undefined behavior.
Add a regression for issue #6151 using 35,000 combining marks.
Testing: meson test -C build --print-errorlogs
Assisted-by: Codex <codex@openai.com>
SubsetGlyph stores borrowed slices into the source glyf table. Faces
created with a table callback may return a fresh blob on each request,
so destroying the population accelerator left those slices dangling
before they were serialized.
Retain the exact glyf blob through serialization. Exercise this path
by making the existing create-for-tables test return copied blobs.
Reported by WinD39 - Huynh Dinh Vu.
Fixes: https://issues.chromium.org/issues/536584255
Assisted-by: OpenAI Codex <codex@openai.com>
The fragment shader picks one horizontal and one vertical band from
the fragment position and walks only that band's curve list, so a
curve must be listed in every band its bounding box reaches into.
The encoder computed those bounding boxes from the unquantized
control points, but the shader only ever sees the coordinates after
they are rounded to quarter font units. When rounding pushed a
curve's extreme across a band boundary, the curve was left out of the
band it now reached into. Fragments landing in that sliver never saw
the curve, so their winding number was off by one and the pixel came
out empty in the middle of a filled area -- a thin black line through
the glyph, appearing and disappearing as the font size moves the
pixel grid.
The rounding error is at most an eighth of a font unit, so this is
invisible for an integer-coordinate glyph rendered at its own upem.
It gets easy to hit when the coordinates are fractional: CFF glyphs
after cu2qu, or any font whose hb_font_t scale is not its upem. With
hb_font_set_scale(font, 163, 163), as in issue #6131, more than half
of the glyphs of util/gpu/default-font.ttf had at least one band the
shader could reach but that did not list the curve.
Compute the bounds (and the is_horizontal/is_vertical tests) from the
quantized control points instead, and widen the band range by 1/1024
of a band so that the double arithmetic here cannot disagree with the
shader's float32 band index right at a boundary.
Verified with a CPU port of _hb_gpu_slug_single: comparing the banded
lookup against a walk over every curve of the glyph, at sizes 39, 47
and 107 with scale 163, default-font.ttf had 27 wrong pixels before
and none after. Encoded atlas size grows by 0.12%.
Adds test_encode_band_membership, which checks the invariant directly
on the encoded blob and fails before this change.
Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
For fetching various bit fields scattered around OpenType tables. Many of
these are legacy or unreliable, but applications might need them for
various legacy reasons.
Fixes https://github.com/harfbuzz/harfbuzz/issues/1920
* [test/fuzzing] Skip hb-depend-closure-parity without GLib
It depends on GLib unlike the other fuzzers.
* [ci] Build the msan bot without external dependencies
We don’t care about msan errors in code that is not ours, and some
libraries like GLib are not built with memory sanitizers in mind.
* [ci] Don't pipe sanitizer test output
The pipe was masking meson exit status, and it was redundant anyway
since the sanitizer output is is already symbolized and demangled.
* [COLR] Fix integer overflow in get_extents
Use to_glyph_extents(), which guards against this.
Update test expectation since we now round instead of truncate.
* [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.
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
The subset umbrella header already carries the public subset API, but it
missed hb-subset-serialize.h even though the serialize symbols are part
of the subset section. Include the serialize header from hb-subset.h so
users can get the API through the top-level subset header.
Keep hb-subset-serialize.h directly includable for compatibility, but
emit a diagnostic asking users to include hb-subset.h instead. Update the
local repacker tests to use the umbrella header and verify the API is
available there.
Testing: meson compile -C build test/api/test-subset-repacker test/fuzzing/hb-repacker-fuzzer
Testing: meson test -C build --suite api
Testing: meson test -C build
Assisted-by: OpenAI Codex
The dependency test passes layout_tag to find_dependency() as an
in/out parameter. Initialize it to HB_TAG_NONE so the helper treats it
as an output slot instead of filtering by an indeterminate stack value.
Testing: meson test -C build --suite api
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.
_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>
Make the coordinate comparison tag-based (self-contained pinned axes
are removed from the instance entirely; their baked contribution is
validated by the rendering checks) and the expected axis count
parametric.
New subtests: pinning opsz (NO_VARIATION_INDEX) off its default drops
the axis and bakes its constant final coordinate; pinning wdth combined
with a wght range restriction drops wdth while wght keeps offset
compensation (including wdth's constant push on wght's final
coordinate, re-added as a free-axis bias). The pin-at-default subtest
now expects wdth to be removed rather than kept hidden.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Extend TestAvar2Instance.ttf with a HIDDEN parametric axis XTRA
(driven by wght through a new avar2 delta row, final coord spanning
[-0.2, +0.3]), a gvar table for 'A' (tuples on XTRA inside and outside
the reachable range, on wght, and on GRAD), and an HVAR table with
matching regions.
The new culling subtest restricts wght to 300:400:500 and checks, over
a grid of retained locations, that final normalized coordinates AND
rendering-level outputs (advance width, glyph extents) match the
original font, and that the instanced gvar and HVAR shrank. The
moved-default subtest also gains rendering checks.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add TestAvar2Instance.ttf, a 1.6KB fontTools-built avar2 font with five
axes (wght, wdth, GRAD, XOPQ, opsz), interior avar v1 breakpoints on
wght, XOPQ and opsz, a wght delta row driven by wdth, a single delta
row shared by GRAD and XOPQ (driven by wght), wdth and opsz mapped to
NO_VARIATION_INDEX, and opsz's default near its axis minimum (so a
far-moved default makes the retained avar v1 segment steep in the new
space, the quantization-limited regime for offset compensation).
test-subset-avar2.c checks that a partial instance produces the same
final normalized coordinates (hb_font_get_var_coords_normalized: fvar
+ avar v1 + avar v2) as the original font at the same user-space
location, within 2 F2Dot14 units (5 for the steepest case, chosen one
unit below what dropping the interior-breakpoint collection produces,
verified by mutation testing), over grids of locations including the
exact kink positions. The eleven subtests cover: same-default and
moved-default restriction (both directions), shared-varIdx rows
(restricted, pinned, and both restricted), pinning at and off the
default, a pinned axis driven by a free axis, NO_VARIATION_INDEX axes
(fresh VarData creation), interior avar v1 breakpoints, and steep
moved-far-from-min defaults.
The subtests abort without the three preceding fixes.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.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.
The SECTION annotation in hb-depend.cc used the old name "hb-depend"
which didn't match the "hb-subset-depend" FILE name in sections.txt
after the header rename. This caused gtkdoc to report the section
description as unused and the section symbols as undocumented. Also
add HB_SUBSET_DEPEND_EDGE_FLAGS_T_DEFINED to a Private subsection
so gtkdoc doesn't flag it as an unused declaration.
The header move from hb.h to hb-subset.h (e3e754f9c) also left
util/hb-subset-depend.cc and test/api/test-ot-depend.c without
access to hb-subset-depend.h, causing build failures on sanitizer
CI jobs that build the utility and test. Add the missing
#include <hb-subset.h> to both.
Assisted-by: Claude <noreply@anthropic.com>
Follows HarfBuzz convention: return total count, take start_offset +
entry_count IN/OUT + entries array. This allows callers to query the
total without filling, page through entries, or fetch all at once.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Rename all public symbols hb_depend_* → hb_subset_depend_*
- Rename hb_depend_t → hb_subset_depend_t
- Replace get_glyph_entry (multi out-param) with lookup_glyph (fills
hb_subset_depend_entry_t struct; fields use ligature_set_index /
context_set_index)
- Rename get_set_from_index → lookup_set
- Remove hb_depend_print from public API (util/hb-subset-depend TODO)
- Move hb_subset_depend_edge_flags_t to hb-depend.h; apply
HB_MARK_AS_FLAG_T in hb-depend-data.hh (internal header only, since
hb-algs.hh is not available in public headers)
- Rename HB_DEPEND_EDGE_FLAG_* → HB_SUBSET_DEPEND_EDGE_FLAG_*
- Update gen-def.py, check-symbols.py, and all test callers
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace HB_DEPEND_API with HB_NO_SUBSET_DEPEND gated on HB_EXPERIMENTAL_API
and HB_LEAN in hb-config.hh, with HB_SUBSET_DEPEND_API opt-in to allow
enabling without full experimental API. Remove depend_api meson option;
depend tests now build under experimental_api=true. Fold depend symbols into
experimental symbols in gen-def.py.
Internal fixes: use free_set_list.pop(), push_or_fail() for allocation safety,
return const hb_set_t* from internal get_set_from_index. Ligature.hh: use
hb_sink iterator, rename ligset→ligset_idx, source→gid. Remove stale
test_depend_cmap unit test (cmap extraction was removed in d4d4c635).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Instead of just checking that the ligature set is non-empty, now verify
it contains the expected component glyphs (1823 and 1829) that form the
ligature 1910 (uni03020300).
This matches the validation pattern used in the NotoSans-Bold test and
provides proper regression testing.
Enhance test_depend_gsub_formats to fully exercise the ligature set API
for SourceSansPro-Regular.otf, not just check that a set index is returned.
Changes:
- Create temporary set to retrieve ligature set contents
- Call hb_depend_get_set_from_index to retrieve the set
- Verify the set is non-empty (contains component glyphs)
- Log the number of components found
- Destroy temporary set
This matches the validation pattern used in the NotoSans-Bold test and
ensures the full depend API is exercised consistently across all
ligature tests.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit addresses multiple code review comments:
1. Switch RNG to std::mt19937 for deterministic tests
- Replace std::rand/srand with std::mt19937 in parity checker
- Use std::uniform_int_distribution for all random number generation
- Ensures test determinism across platforms for non-error-injection tests
2. Convert debug fprintf to DEBUG_MSG_LEVEL
- Convert GSUB lookup processing prints to DEBUG_MSG_LEVEL(DEPEND, nullptr, 1, 0, ...)
- Visible at HB_DEBUG_DEPEND=2 or higher for detailed per-lookup debugging
3. Rename function for consistency
- hb_depend_from_face → hb_depend_from_face_or_fail
- Follows HarfBuzz convention for functions returning nullptr on failure
- Update all call sites, documentation, and code comments
4. Adopt established set deduplication pattern
- Change from hb_vector_t<hb_set_t> to hb_vector_t<hb::unique_ptr<hb_set_t>>
- Use pointer-based hashmap: hb_hashmap_t<const hb_set_t*, hb_codepoint_t>
- Leverages hb_hash's content-based deduplication via pointer dereferencing
- Follows pattern established elsewhere in HarfBuzz codebase
5. Separate ligature and context set semantics
- Rename free_set → free_ligature_set (no hashmap manipulation)
- Rename new_set → new_ligature_set (no hashmap manipulation)
- Rename find_or_create_set → find_or_create_context_set (only function using hashmap)
- Makes it explicit which sets are deduplicated (context) vs unique (ligature)
- Update all call sites in Ligature.hh, ReverseChainSingleSubstFormat1.hh, hb-ot-layout-gsubgpos.hh
6. Code cleanup
- Remove unused add_to_ligature_set function (dead code)
- Refactor new_ligature_set(cp) to delegate to new_ligature_set(set)
- Move set_to_index declaration near sets/free_set_list for better organization
All tests pass.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Edges created from non-zero positions in multi-position contextual rules
can consume intermediate glyphs (glyphs produced then immediately consumed,
never settling in closure). This causes depend's closure to include extra
glyphs compared to subset's closure, which is expected behavior.
Added HB_DEPEND_EDGE_FLAG_FROM_CONTEXT_POSITION flag to mark these edges
at extraction time. Updated parity checker to track when such edges are
hit during closure computation and distinguish between:
- Expected over-approximation (hit flagged edge): informational only
- Unexpected over-approximation (no flagged edge): critical error
This enables detection of genuine bugs (unexpected over-approximation)
while allowing expected cases from intermediate glyphs.
Updated all API callers and documentation to include nullable flags
parameter. Renamed parity checker terminology from "fuzzer" to "parity"
for clarity.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>