Extend the lookup-variation fixture with a GDEF ItemVariationStore-backed
ConditionValue and a GPOS conditional positioning lookup. This covers
variation-index evaluation, GPOS shaping, and lookup collection while
reusing the existing partial-instancing checks.
Tested with the full Meson suite and OTS validation of the fixture.
Assisted-by: OpenAI Codex <codex@openai.com>
Reduce LookupVariationRecord conditions to false, true, or a residual
condition when axes are pinned or restricted. Fold compound AND, OR,
and NOT conditions, remap value-condition variation indices, and emit a
constant condition when a surviving lookup becomes unconditional.
Extend the test font with a second axis and all condition formats so the
subset tests cover structural, full, and partial instancing behavior.
Tested with the full Meson test suite, targeted Clang HB_NO_VAR and GCC
builds, and OTS validation of the fixture.
Assisted-by: OpenAI Codex <codex@openai.com>
Resolve lookup variations at the pinned coordinates and store their final
lookup sets in the subset plan. Use those sets when serializing the main
Feature tables before dropping FeatureVariations from a full instance.
This reuses the shaping resolver so version 1.0 feature substitutions,
ADD_DEFAULT_LOOKUPS, compound conditions, and GDEF variation data are
evaluated consistently.
Tested with the full Meson test suite and a targeted HB_NO_VAR build.
Assisted-by: OpenAI Codex <codex@openai.com>
Subset FeatureVariations 1.1 lookup records while remapping feature and
lookup indices. Preserve all condition formats and remap variation
indices used by value conditions.
Keep features with lookup variations distinct during feature
deduplication, since equal default lookup lists do not imply equal
variable behavior.
Tested with the full Meson test suite and a targeted HB_NO_VAR build.
Assisted-by: OpenAI Codex <codex@openai.com>
Include conditionally referenced lookups in layout collection, feature
closure, and GSUB dependency data. Also retain variation indices used
by FeatureVariations conditions in GSUB and GPOS when remapping the
GDEF variation store.
Tested with the full Meson test suite and targeted HB_NO_VAR builds of
the touched runtime translation units.
Assisted-by: OpenAI Codex <codex@openai.com>
Parse and sanitize the FeatureVariations 1.1 lookup-oriented records.
Resolve their effective lookup sets while constructing the shape-plan
key so cache entries remain exact without retaining raw coordinates.
Handle ADD_DEFAULT_LOOKUPS, multiple matching conditions, and the
interaction with version 1.0 feature substitutions. Keep the existing
public FeatureVariations query API behavior unchanged.
Tested with the full Meson test suite.
Assisted-by: OpenAI Codex <codex@openai.com>
Encode versions 1.0 and 2.0 in the VORG fixtures instead of the undefined
minor version 1. The test behavior is unchanged, but the input now conforms
to the final Open Font Format definition.
Tested with test-be-subset-tables and the full Meson suite.
Assisted-by: OpenAI Codex <codex@openai.com>
Consult DMAP before cmap for nominal and variation mappings, and combine
their character coverage while retaining DMAP precedence. Reuse the cmap
parser and serializer for DMAP, including effective subsetting closure.
Keep DMAP available independently of beyond-64K support; only cmap format
15 remains conditional.
Tested with the full Meson suite and with an HB_NO_BEYOND_64K build.
Assisted-by: OpenAI Codex <codex@openai.com>
Account for the uint24 glyphCount field when reserving the uppercase
GVAR header. The fixed 20-byte size caused the final byte of the
glyphVariationDataArrayOffset to overlap the first array offset.
Add an exact binary subsetting regression for the 21-byte header.
Testing: meson test -C build --print-errorlogs
Assisted-by: OpenAI Codex
Use the final version 1.4 header with five appended Offset32 fields
instead of the obsolete major-version-2 layout. Honor each nonzero
Offset2 field in preference to its legacy counterpart when reading and
subsetting the table.
Add a binary regression test that gives the legacy and extended glyph
class definitions different values, ensuring the extended field wins.
Testing: meson test -C build
Assisted-by: OpenAI Codex <codex@openai.com>
Reconcile the beyond-64K table type changes with the dependency API,
graph result handling, and variation-budget updates from main. Preserve
the branch's wider table variants while adopting the new behavior.
Build and test with Meson (281 passed, 1 skipped).
Assisted-by: OpenAI Codex <noreply@openai.com>
on a stream-backed FT_Face
hb_ft_font_set_funcs() creates its own internal FT_Face from the
font's face blob, and hooks that blob to the FT_Face's generic
finalizer (_release_blob), with the shared static FT_Library hooked
to the blob's user-data destructor (destroy_ft_library).
On hb_font_destroy(), _hb_ft_face_destroy_static() locks
static_ft_library_mutex and calls FT_Done_Face(), which synchronously
runs the finalizer chain: _release_blob() -> hb_blob_destroy(). For a
face created from a custom FreeType stream (FT_OPEN_STREAM), each
hb_face_reference_blob() call synthesizes a brand-new, unshared blob
(via _hb_ft_reference_table()), so this hb_blob_destroy() call drops
it straight to zero, which triggers destroy_ft_library(), which tries
to lock the same non-recursive static_ft_library_mutex again on the
same thread. Self-deadlock.
This didn't reproduce for a file-path or memory-blob face, because
there the blob handed to the internal FT_Face is the same blob shared
by the outer hb_face_t, so the drop inside the lock only decrements
its refcount without reaching zero; the final unref (and
destroy_ft_library() call) happens later, outside the lock, when the
outer face itself is destroyed.
Fix by holding an extra reference on the blob across the locked
FT_Done_Face() call, so it can only reach a zero refcount (and invoke
destroy_ft_library()) after static_ft_library_mutex has been
released. FT_Done_Face() itself remains fully serialized, as intended
by 46644f885d.
Fixes: https://github.com/harfbuzz/harfbuzz/issues/6276
Tests: meson test -C build (260/260 passed); added
test_native_ft_set_funcs_stream_face_no_deadlock to test/api/test-ft.c,
which hangs on unfixed code and passes with the fix. Also verified
against the reporter's original repro.c.
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
* [font] fix signed integer overflow in synthetic_glyph_extents
synthetic_glyph_extents applies synthetic slant and embolden to a
glyph's extents with plain hb_position_t arithmetic: x_bearing +
width and y_bearing + height in the slant branch, plus the += / -=
shifts in the embolden branch. glyf's contour_bounds_t and the sbix
png-dimension path each clamp x_bearing/width and y_bearing/height to
the full hb_position_t range independently via
hb_clamp_to<hb_position_t>(), so one field can reach INT32_MIN/MAX on
its own and the sum overflows, which is undefined behavior (UBSan
signed-integer-overflow at hb-font.hh:221). Reached from
hb_font_get_glyph_extents when synthetic slant/bold is set and the
glyph has extents but no drawable outline.
This is the sibling of 873dbc1 (scale_glyph_extents), which fixed the
same x_bearing + width overflow in the adjacent function. Accumulate
the slant terms in double and the embolden terms in int64, saturating
each result to hb_position_t with hb_clamp_to, matching that fix and
the copy in hb-ft.cc. Valid in-range extents are unchanged.
Add a regression test in test/api/test-font.c that drives the sink
with INT32-extreme extents; it aborts under the asan/ubsan job without
the fix. Full meson test -C build stays green.
* [font] use int64_t for slant accumulation in synthetic_glyph_extents
The analytic rasterizer stored every row's area and cover in 32- and
16-bit accumulators. Highly overlapping outlines could exceed those
ranges and trigger signed overflow before coverage was clamped.
Keep compact SIMD accumulators for rows with at most 127 active edges.
Lazily use 64-bit scalar accumulators for denser rows, where the narrow
cover bound no longer holds. Add regressions for area overflow and
cover wrapping.
Tested with meson test -C build, the ASan/UBSan raster API test, all
raster fuzzer corpus chunks, and the supplied reproducer.
Assisted-by: OpenAI Codex <noreply@openai.com>
Update the generated Unicode and language-tag tables for Unicode 18.0.
Add script values for Jurchen, Proto-Cuneiform, and Seal, route them
through USE, and select ideographic baselines for Jurchen and Seal.
Document the new script values and extend Unicode and baseline tests.
Tested with meson test -C build: 278 passed, 1 skipped, 0 failed.
Assisted-by: Codex <codex@openai.com>
Verify that VARC component coordinates can address axes retained in gvar
when a static font has no fvar table.
Tested with the full Meson test suite.
Assisted-by: Codex <codex@openai.com>
* Add null checking and fix memory leak in hb-coretext.cc
Assisted by: Gemini
* Add RAII hb_cf_ptr_t to manage coretext object lifetimes.
* Remove HAVE_CORETEXT guard in hb-coretext.hh
hb-coretext.hh will only be included when HAVE_CORETEXT is defined, so no need for the guard.
Short-circuit unchanged-index checks and simplify glyph closure to use
one pending set with the output glyph set tracking visited glyphs.
Strengthen retained-glyph-ID coverage by comparing the source and subset
outlines using the original glyph ID.
Tested with: meson test -C build --print-errorlogs
Assisted-by: OpenAI Codex <openai-codex@users.noreply.github.com>
Propagate allocation and component-decoding failures from VARC closure
instead of continuing with an incomplete glyph set. Treat malformed VARC
records as dependency-extraction failures as well.
Document VARC dependency edges and exercise subset variation-store
remapping at non-default coordinates.
Tested with:
- meson test -C build
- standalone lean and world syntax checks
- CMake harfbuzz-subset build
Assisted-by: OpenAI Codex <openai-codex@users.noreply.github.com>
Resolve the VARC record-decoding conflict by preserving the shared
decoder while threading main's rendering budget through axis and
variation work.
Tests: meson test -C build (277 passed, 1 skipped)
Assisted-by: OpenAI Codex <codex@openai.com>
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>
raster-paint reached into the rasterizer through two internal functions:
hb_raster_draw_set_external_work() to inject a shared work counter and
hb_raster_draw_get_edge_work() to read scanline cost back. Both are gone.
The paint session now carries two budgets for two different resources:
- The outline budget bounds glyph outline traversal and curve
flattening. It is the public draw/paint budget: raster-paint seeds the
rasterizer with hb_draw_set_budget() before each glyph and reads the
remainder back with hb_draw_get_budget_remaining(), so a whole COLR
walk shares one budget without touching rasterizer internals.
- The pixel budget bounds scanline and fill work, which scales with
surface area, not outline complexity. It is charged from the public
extents of the rendered mask (and other pixel areas) and keeps its
surface-sized default. An unlimited outline policy disables it too.
Folding pixel work into the outline budget was why the default had to be
inflated by the surface passes; the two now live apart, so HB_BUDGET_GLYPH
is a pure outline budget and the surface scaling belongs to the pixel
budget. Standalone hb_raster_draw is unchanged: it draws once, so its
scanline work needs no session budget, only its structural caps.
COLR drives only push_clip_glyph, whose seed/emit/readback is a single
self-contained step, so the aggregate outline budget is always conserved
across a COLR walk. The push_clip_path_start/end pair spans client draw
calls; like push/pop it must be balanced by the client for the outline
budget to reconcile, and each render is still bounded by the rasterizer's
structural caps regardless. hb_draw_set_budget() clamps a negative seed
to zero, so outline exhaustion does not latch across glyphs; an empty
mask can then be rendered once more, but that path is bounded by the
pixel budget.
Add a regression test that paints a real multi-layer COLR glyph into a
1x1 surface (unbounded pixel budget) and checks the outline budget both
aggregates the layers' work and bounds the walk.
Tests: meson test -C build (275/275 passed); the raster and gpu COLR
regression seeds complete in 0.40s and 0.44s.
Assisted-by: Claude <noreply@anthropic.com>
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.