Use HB_BUDGET_GLYPH as the common finite default for VARC and the
in-house draw and paint backends. Raster paint retains its surface-size
scaling so large targets still permit a small number of full passes.
Remove redundant exhaustion checks around hb_budget_spend(). A spend
that lands exactly on zero succeeds; only a negative live value latches
exhaustion. Apply the same boundary consistently to postcharged
renderer work and cover the next positive-cost attempt in tests.
The full Meson suite passes, as do the full TSan suite and the three
rendering regression seeds under ASan and UBSan.
Assisted-by: OpenAI Codex <codex@openai.com>
Cairo's user-font rendering acquires two internal locks in both
orders. The new nested-rendering regression test exposes that existing
lock-order inversion under ThreadSanitizer, including when run against
an unmodified HarfBuzz.
Keep the end-to-end test enabled normally, but skip that workload when
compiled with TSan instead of suppressing deadlock detection globally.
Assisted-by: OpenAI Codex <codex@openai.com>
Exercise CFF work accounting through the public draw-budget callbacks.
Use lower bounds above each parent charstring's flat operator cost so the
CFF1 assertion covers both seac children and the CFF2 assertion covers
proportional blend work.
Keep the interpreter's local cost type consistent with the unsigned spend
interface.
Tests: meson test -C build (275/275 passed)
Assisted-by: OpenAI Codex <codex@openai.com>
Cairo's draw callbacks previously received a raw cairo_t, so paint-driven
outline traversals could not share a renderer budget. Nested color glyphs
also construct fresh HarfBuzz paint contexts while populating the same
scaled-font glyph cache.
Attach a finite budget owner to the scaled font and let each draw/paint
context borrow it. Recharge only for the outermost glyph callback, expose
the budget callbacks on both function sets, and charge emitted path and
nested color-glyph work. Exercise the original vector timeout seed through
the Cairo user-font renderer.
Tests: meson test -C build (275/275 passed)
Assisted-by: OpenAI Codex <codex@openai.com>
Synthetic slant and emboldening first render into an outline recorder.
That adapter previously hid the renderer's live budget, allowing the
underlying outline traversal to use a fresh per-glyph allowance.
Forward the destination draw data's remaining-budget pointer through
the recorder. Add a regression test proving an exhausted synthetic
draw fails against the caller's budget.
Assisted-by: OpenAI Codex <codex@openai.com>
Make VARC record traversal, variation processing, and all glyf/CFF
leaves consume the renderer-owned live counter. Forward that counter
through the transforming pen and make leaf traversal obtain it from
the active draw session.
Keep a finite standalone allowance for extents, charge records even
when conditions suppress their components, and add public-callback
coverage for cumulative depletion and exhaustion.
Tests: meson test -C build (274/274 passed)
Assisted-by: OpenAI Codex <codex@openai.com>
Store finite budget policy and live state on GPU draw and paint
contexts. Charge generated curves against the draw context and make
paint-owned scratch draws borrow the paint session's counter.
Propagate the same live counter through both identity clip extraction
and the transforming forwarding pen. Preserve policy across clear and
restore DEFAULT on reset, with focused lifecycle and propagation tests.
The ClusterFuzz GPU timeout seed completes in 0.11 seconds in the
optimized build.
Tests: meson test -C build (273/273 passed)
Assisted-by: OpenAI Codex <codex@openai.com>
Store budget policy and live state on raster draw and paint contexts.
Make outline traversal and curve flattening borrow the paint session's
live counter, while standalone draw keeps its own finite session counter.
Preserve raster's dynamic surface-sized default, resolving it only after
initialization and never replacing concrete or unlimited client policy.
Recharge on clear and restore DEFAULT on reset. Add lifecycle and lazy
default coverage.
Tests: meson test -C build (273/273 passed)
Assisted-by: OpenAI Codex <codex@openai.com>
Expose budget policy and remaining-work callbacks on draw and paint function
objects. The public setters clamp invalid negative caps, distinguish finite
defaults from explicit unlimited operation, and report whether a backend
participates in accounting.
Let draw sessions borrow the live counter owned by draw_data. OpenType glyf
and CFF traversal then debit the same counter in place, while unsupported
backends retain a finite per-glyph fallback. Forward budget access through
the parent-font draw adaptor.
Document the new API and cover nil, default, unlimited, clamped, concrete,
and live-depletion behavior.
Tests: meson test -C build (272/272 passed)
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>