The ANT-2026-DQGMHCLX regression was added as a line in
test/shape/data/in-house/tests/variations.tests, but that suite is also
run with --font-funcs=fontations appended by the test runner (which a
.tests line cannot override). Under fontations funcs this multi-
USE_MY_METRICS composite font's advances differ from HarfBuzz's own, so
the line failed CI. The divergence is a real HarfBuzz-vs-fontations
difference in how multiple USE_MY_METRICS components are resolved, not a
HarfBuzz bug: HarfBuzz takes the metrics of the last such component.
Remove the .tests line and pin the same regression in
test/api/test-ot-metrics-tt-var.c instead, using hb_font_get_glyph_h_advance,
so it exercises HarfBuzz's own glyph metrics and the fontations CI run does
not touch it. The font moves to test/api/fonts/ where that test loads it.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
hb-limits.hh states that a session which drives another subsystem
carries one cumulative budget, initialized once per top-level entry and
only ever decremented. When instancing, glyf::subset() drives
Glyph::get_points() once per retained glyph to recompute bounds and
metrics, but passed no budget, so each glyph restarted from a fresh
HB_BUDGET_GLYPH and the table as a whole was bounded only by 2^24 times
the glyph count. A 59 KB font of 2,000 nested composites over a shared
64-level chain made one hb_subset_or_fail() instancing call spend 34 s
of CPU, since the shared chain was re-walked (and re-charged only
against a fresh budget) for every top-level glyph.
Add HB_BUDGET_SUBSET_GLYF and keep the live counter in
hb_subset_context_t, which is constructed once and reused across the
ran-out-of-room retries in _hb_subset_table_try(), so a retry does not
reset it. Thread it through _populate_subset_glyphs() and both
compile_bytes_with_deltas() into get_points(). Exhausting it fails
get_points(), which the existing loop already turns into dropping glyf
from the instance -- the same outcome as any other glyph-load failure
there.
This is one cumulative counter, not a per-glyph budget multiplied by
the glyph count. It is sized at 2^28; measured consumption of the
largest glyf variable font under test/ (MPLUS1-Variable) is ~1.2M
units, about 220x below the cap, and even a font at the 65,535-glyph
maximum stays well under, so real fonts instance unchanged (outputs
byte-identical). One behaviour change: a single glyph is now bounded
by what is left of the table budget rather than by HB_BUDGET_GLYPH, so
one glyph may spend between 2^24 and 2^28 units; the session total is
still bounded.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-5BY15VDS.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
glyf::subset() trims (and, with --no-hinting, walks the components of) every
retained glyph on every serializer retry. The only thing bounding that work
was the implicit assumption that loca is monotonic, so the retained ranges sum
to at most the table. loca need not be monotonic, so any number of glyph IDs
can alias the same bytes, and the work grows as glyph count times glyph size
times retries: a 328 KB font with loca = 0, L, 0, L, ... makes hb-subset spend
~22 s of CPU and then fail, where a same-sized monotonic font takes 0.02 s.
The glyph closure in _populate_gids_to_retain() already fetches each retained
glyph exactly once, before any table is subset, so charge the untrimmed length
there (before the composite operation count can bail out, so every glyph added
to the set is paid for) against a budget of HB_SUBSET_GLYF_MAX_BYTES_FACTOR (16)
times the glyf length, and fail the plan when it is exceeded. This also makes
hb_subset_preprocess() fall back to the source face cheaply.
Fonts with a monotonic loca never exceed a factor of one, so their output is
unchanged; the one behaviour change is that a specification-violating loca that
aliases large glyph bytes more than sixteen tables' worth is now rejected
instead of subsetting slowly.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-S5U7MYJ7.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
In phantom_only mode SimpleGlyph::get_contour_points() reserves a glyph's
declared point count (gvar needs the count to locate the phantoms) but never
loads the points. The composite branch of Glyph::get_points() wrongly assumed
the component's point array is then empty ("Empty in case of phantom_only"):
for a USE_MY_METRICS child it transformed all the reserved points and, after
removing only the four phantoms, left them in all_points to be transformed
again at each enclosing level (up to 64 deep) and counted against
HB_GLYF_MAX_POINTS.
Once the child's phantoms have been copied, skip the transform and shrink
all_points back to old_count in phantom_only mode; the top-level lsb shift
likewise only touches the phantoms in that mode so a simple glyph's reserved
points are not walked either. Output is unchanged (phantoms are copied before
the transform in both modes). The one behavioural change is that advance
lookups no longer fail spuriously when components' unloaded point counts exceed
HB_GLYF_MAX_POINTS (four USE_MY_METRICS copies of a 65536-point glyph now give
the hmtx advance 600 rather than the upem/2 fallback).
Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-0NDQUVPX.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [subset] Clamp PaintColrLayers layer range to LayerList in COLRv1 closure
PaintColrLayers::closurev1() recorded firstLayerIndex ..
firstLayerIndex + numLayers - 1 as retained layers without checking
the range against LayerList.len (PaintColrLayers::sanitize is a plain
check_struct), and _colr_closure() then creates one colrv1_layers map
entry per retained index. A crafted font whose leaf paints point past
the end of the LayerList could therefore add up to 255 entries each for
layers that do not exist, driving subset-plan memory to roughly 1200x
the font size (585 MiB for a 512 KB font).
Clamp the range to the LayerList at the one place the retained-layer set
is built, before add_layer_indices() and for the dispatch loop alike;
this also removes the firstLayerIndex + numLayers wrap-around in the loop
bound. Readers (paint_glyph, dependv1) never record indices and already
tolerate out-of-range ones via LayerList::get_paint() returning Null, so
they are left alone. A PaintColrLayers whose range lies past the source
LayerList now has no mapping and subset writes 0xFFFFFFFF; both that and
a renumbered index past the new LayerList are out of range and draw
nothing.
Adds a regression test that builds such a font inline and pins the
output; it fails without the fix.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-ROQFK0RA.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [subset] Bound shared COLRv0 layer expansion and make V0 closures linear
COLR::subset() gives every retained COLRv0 base glyph a private copy of
its layer range, so N base glyphs sharing L layers cost N x L layer
copies with two hash lookups each, and nothing checked the total against
the 16-bit numLayers header field. serialize_V0() walks the lazy
iterator twice and _hb_subset_table_try() retries while doubling the
buffer, so a ~200 KB font with all records naming the same range kept
hb-subset busy for about two minutes before failing.
Cap the summed layer count with a cheap walk over base_it before layer_it
is built, and drop COLR (return_trace (false)) when the total exceeds
0xFFFF, the same way this function already handles V0 records it cannot
subset; this also removes the 16-bit wrap in serialize_V0(). Any total
above 65535 could only have produced a failed subset or a wrapped,
invalid numLayers, so no valid output is lost.
The two V0 closure helpers had the same N x L shape during planning;
collect the layer indices of all retained base glyphs into one set first
and visit each layer once. closure_glyphs() now takes the glyph set in
one call (the accelerator wrapper changes signature with it; no public
API change), and _colr_closure() passes the whole set instead of looping.
Adds test_subset_colr_shared_layers (256 base glyphs all claiming the
same 256 layers): retaining 255 gives a 65280-layer table, retaining all
256 gives an empty COLR.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-4T7NHCTK.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [subset] Look up each retained glyph's ClipRecord by bsearch in ClipList::subset
ClipList::subset() walked startGlyphID..endGlyphID of every ClipRecord,
which is only O(num_glyphs) overall when the records are sorted and
disjoint. ClipList::sanitize() checks neither, so R overlapping records
each spanning all glyphs cost R x 65535 iterations: a 332 KB font with
10000 whole-range records took about 20 s of CPU in hb-subset whatever
glyphs or text the request asked for.
Invert the loop: iterate the retained glyph set once and find each
glyph's record with clips.as_array ().bsearch (gid), exactly how
ClipList::get_extents() resolves a glyph's clip box when rendering, and
the same shape as the COLRv0 path in COLR::subset(). Cost is now
O(|glyphset| log R) regardless of record overlap. For well-formed
(sorted, disjoint) lists the output is unchanged; for malformed
overlapping/unsorted lists the chosen record can differ (bsearch instead
of last-record-wins), which makes the subset agree with the clip box
HarfBuzz itself renders from the source font.
Adds an extended-format hb-subset-fuzzer input (5000 records covering
all 65535 glyphs) that the subset-fuzzer tests pick up.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-MRSCGMJ7.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [subset] Compute COLR constant_after_pinning once per plan
PaintRadialGradient::constant_after_pinning() answers a question about
the source ItemVariationStore and the subset plan only, yet it rescanned
every variation region (building a hashmap per region, up to 32767) on
every paint visit. Shared paints are visited once per reference by
OffsetTo::serialize_subset(), so during partial instancing the cost grew
as visits x regionCount: 40 s to 6 minutes for a 192 KB font with a
PaintComposite chain and many regions.
Cache the answer in a tri-state plan field (-1 until computed, like the
lazily-set has_gdef_varstore flag) so the scan runs at most once per
plan; the plan is valid for one source face and one set of axis
locations, so this is sound. Move the cheap varIdxBase != NO_VARIATION
test ahead of the scan so non-variable format 6 gradients never trigger
it. The allocation-failure path of get_var_region() still sets the
serializer error and returns uncached, as before.
Output is byte-identical; the attack font drops from ~41 s to ~0.03 s.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-910I4C0Y.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [COLR] Charge gradient color stops to the paint session work budget
The COLRv1 paint walk bounds paint-table visits (HB_MAX_NESTING_LEVEL,
HB_MAX_GRAPH_EDGE_COUNT) but handed out ColorLine stops uncharged, so a
single 65535-stop ColorLine shared across up to 16384 gradient edges
could deliver ~10^9 stops from one hb_font_paint_glyph() call, keeping
the rendering thread busy for minutes per glyph in every backend.
Give hb_paint_context_t the session's live budget via
funcs->get_budget_remaining_ptr(), with the same local HB_BUDGET_GLYPH
fallback hb_draw_session_t uses, charge HB_BUDGET_16 per stop delivered
in ColorLine::get_color_stops() (the one place every consumer fetches
stops, so vector, raster, cairo and client paint functions are all
covered), and make recurse() skip further paints once the budget is
negative, as it already does for an oversized graph. The backend's one
budget is only spent, never re-armed, so this does not reintroduce the
cross-subsystem budget multiplication removed in #6147. hb-ft-colr.hh
has the same shape and gets the identical change.
With the default 2^24 budget about a million stops per session are
delivered before the rest of the walk is skipped best-effort. A
separate quadratic cost inside cairo's own gradient pattern building is
not addressed here. Adds a regression test that fails without the fix.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-F2NWHRVP.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [paint] Clip sweep-gradient tiles to 0..2π in hb_paint_sweep_gradient_tiles
hb_paint_sweep_gradient_tiles() documents that it iterates the 0..2π
sweep, and all three consumers (hb-cairo mesh patches, the SVG and PDF
writers) size their per-tile loops by tile width on that assumption.
Several emit sites (the start==end PAD case, the first PAD stop past 0,
and repeat/reflect segments straddling 0 or 2π) passed the angles
straight through, and COLRv1 variation deltas can place them hundreds of
thousands of radians outside the circle, so one tile could expand to
millions of patches: a 504-byte variable font drawn off its default
allocated ~1.6 GiB through hb-cairo.
#6157 bounded the number of sweep tiles; this bounds the width of each
one. Route every emit through a small clipping lambda inside the tiler
that clamps the tile to [0, 2π], lerps the end colours at the clip
points, and drops tiles entirely outside, so the contract holds at the
single place it is established rather than in each backend.
HB_PAINT_MAX_SWEEP_TILES and the repeat-loop bounds are untouched;
external callers need no change.
Adds a regression test calling the public function with far-out angles
for PAD/REPEAT/REFLECT; it fails without the fix.
Follow-up to #6157.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-GCNW3SND.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [depend] Bound COLR dependency extraction with a shared op budget
COLR::depend() walked the COLRv1 paint graph from scratch for every
BaseGlyphPaintRecord (clearing the visited set each time) with no total
work limit, so N base glyphs sharing one paint graph cost N times the
graph, quadratic in table size (204 s for a 200 KB font); the COLRv0
loop has the same base-glyphs x layers shape. The API is built only
with -Dexperimental_api=true.
hb_colrv1_depend_context_t, which already owns the per-walk depth and
visited-set guards, now also carries max_ops sized like the sanitizer's
(table length x HB_SANITIZE_MAX_OPS_FACTOR, clamped to the MIN/MAX),
charged one unit per Paint::dispatch(), per COLRv0 layer record, and per
PaintColrLayers layer run. Charging the layer run in dependv1() matters
because a layer resolving to the null or an unknown-format paint is
dropped by Paint::dispatch() before it reaches the context, so without
it a PaintColrLayers could still spin its 255-iteration loop uncharged.
Exhausting the budget calls depend_data->fail() (the existing error
idiom) so hb_subset_depend_from_face_or_fail() returns NULL rather than
a graph with silently missing edges, and the base-glyph loop stops once
the builder has failed.
The reproducer font is now rejected in a fraction of a second; the
control still succeeds, and legitimate fonts keep 64 ops per table byte
of headroom. Adds test_depend_colr_budget.
Follow-up to #6113.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-TO8ND880.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [ft] Drop the dead color-stop iterator resets
Since the color line is copied locally ("Keep iteration local"), the
iteration advances cl->color_stop_iterator on that local copy, which is
discarded when the function returns. The two "reset the iterator for next
time" writes (cl->color_stop_iterator = iter) therefore have no effect:
there is no persistent iterator state to restore, and positioning across
calls is driven entirely by the start argument.
Remove both dead writes and the now-unused saved iterator. No behavior
change; the return value (num_color_stops) is unaffected by iteration.
Full test suite passes (277/277).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
* [raster] Bound embedded PNG dimensions before decoding
hb_raster_paint_image() handed a font's embedded sbix/CBDT PNG to
deserialize_from_png(), which allocated and filled the whole image at
whatever size the PNG's IHDR declared (up to two buffers at the 1 GiB
HB_RASTER_MAX_BUFFER_SIZE cap each), and only charged src_width *
src_height against the pixel budget after the decode had finished. A
33 KB sbix font with a blank 16384x16384 1-bit PNG therefore made the
raster backend allocate and touch ~2 GiB of memory per painted glyph,
independent of the requested output size.
Surfaces whose size comes from font data are already clamped to
HB_RASTER_MAX_AUTO_DIMENSION (4096 per side); the PNG decoder was not.
deserialize_from_png() gains a max_dimension parameter checked right
after png_get_IHDR(), before any allocation, and the paint callback
passes HB_RASTER_MAX_AUTO_DIMENSION. The public
hb_raster_image_deserialize_from_png_or_fail() keeps its INT_MAX
behaviour through the default argument, matching the limit's documented
intent that explicitly requested sizes are not bounded. With the cap a
decode is at most 16M pixels, whose cost fits the 2^26 pixel budget, so
the later charge_work() is adequate.
Behaviour change: sbix/CBDT PNG glyphs wider or taller than 4096 pixels
are no longer painted by the raster backend (the callback returns false,
as for any undecodable image). The cairo backend has the same weakness
on a different code path and was already fixed separately (#6497).
test_image_png_size() in test/api/test-raster.cc paints a 4096- and a
4097-pixel-wide PNG and checks that only the former lands; it fails on
the unpatched library.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-ENME4ECM.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [raster] Charge the scanline sweep to the pixel budget
hb_raster_draw_render() walks every active edge once per pixel row it
spans, a product (edges times rows) that neither HB_RASTER_MAX_DRAW_EDGES
(2^20) nor HB_RASTER_MAX_AUTO_DIMENSION (4096 rows) bounds, and that
nothing charged: the outline budget only sees traversal and curve
flattening. A 10 KB glyf font of 199,800 full-height straight edges
therefore cost tens of seconds of CPU for a single render.
PR #6244 added the precharge for the paint path but sized it by the paint
*surface*, which comes from the font's declared glyph extents, while the
mask rasterizer auto-sizes the mask from the outline itself; a 1x1
ClipBox or empty bounding box slipped the full-height sweep past it. The
direct draw path had no check at all.
This charges the sweep inside hb_raster_draw_render(), where the extents
really rendered are known, estimating it with the existing
hb_raster_draw_get_pixel_work() helper, now clamped to those extents (the
fixed ones, else the 4096 auto cap) rather than taking them as arguments.
The sweep is skipped when the estimate exceeds the per-session pixel
allowance raster-paint already uses, max(HB_BUDGET_RASTER_PIXELS,
HB_BUDGET_RASTER_PAINT_PASSES * width * height). The two paint callers
now use the mask-relative estimate, and hb_raster_paint_attach_clip_rdr()
seeds HB_BUDGET_UNLIMITED into the mask rasterizer when the paint policy
is unlimited, so opting out of limits still disables the check.
hb_raster_draw_get_pixel_work() is HB_INTERNAL, so dropping its two
arguments changes no public API/ABI.
Behaviour change: an over-budget render returns a blank image of the
computed size (documented in the API comment) rather than NULL. Letting
HB_BUDGET_UNLIMITED switch the check off matches the paint pixel budget's
semantics and keeps the edge and dimension caps active; whether this
bound should instead be an unconditional structural cap is a maintainer's
choice.
Testing: the finding's reproducer flips from BUG to OK, its attack render
dropping from ~39 s to 0.05 s of CPU while the control is unchanged; the
api suite passes under both the optimized and the ASan/UBSan build.
test_budget_sweep in test/api/test-raster.cc covers the direct draw path
with auto and fixed extents and the small-surface paint-clip path.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-8PTXE0MD.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
get_default_loader_name() cached the pointer returned by
getenv("HB_FACE_LOADER") for the process lifetime. That storage is
owned by the C runtime or the caller and may change or be freed after
the lookup, leaving the cached pointer dangling.
Duplicate the value on first use and hold onto the copy, rather than
caching the borrowed pointer or calling getenv() on every face load.
Use the existing hb_lazy_loader_t pattern (as static_face_loader_list
does): an unset or empty value, or an allocation failure, caches the
empty-string default; a non-empty value is copied with hb_malloc and
freed via hb_atexit.
Add an api smoke test that loads the fixture through the file and blob
default-loader entry points (loader == NULL) with HB_FACE_LOADER set,
then restores the caller's environment. Its value is LSan coverage of
the copy-and-free path in the asan-ubsan job; glibc's setenv() does not
free replaced strings, so the borrowed-pointer bug is not observable on
Linux. Verified: full meson test suite (275 tests) and test-face under
ASan/UBSan with leak detection enabled both pass.
Alternative to #6493, following review feedback there.
Assisted-by: Claude Opus 4.8 <noreply@anthropic.com>
test_shape_overlong_cluster_remerge checks the native cluster re-merge op
budget added in hb-buffer.cc, which only the "ot" shaper exercises. Under
HB_SHAPER_LIST=harfrust the harfrust shaper handles clusters itself and
never trips that budget, so the buffer stayed allocation-successful and the
test aborted in the rust CI job. Pin the test to hb_shape_full() with an
"ot" shaper list.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The per-shaper lazy loaders (hb_shaper_lazy_loader_t) declare nullptr
as their null object, so hb_lazy_loader_t::get_stored() cannot tell
"create() failed" from "not created yet" and re-runs create() on
every access. hb_shape_plan_key_t::init() tests face->data.graphite2
before the plan cache is consulted, so a font whose Silf table
Graphite2 rejects paid a full gr_make_face_with_ops() on every
hb_shape() call for the life of the face -- CPU cost unbounded by
max_ops/max_len, which apply only once the buffer is processed.
The loader already has the mechanism for this: tag_null stores a
failed create() as get_null() with bit 0 set, and get_stored()/
operator bool()/do_destroy() mask or recognize it by that bit.
Opt the shaper loaders into tag_null, fixing every shaper's face and
font data at once, as the table and accelerator loaders already do.
HB_SHAPER_DATA_SUCCEEDED moves from (void *) +1 to (void *) +2 so the
success sentinel no longer collides with the tagged null (nullptr | 1
== (void *) 1); its no-op destroy functions never dereference it.
hb_font_t's data.fini() on font changes still resets the font-data
loaders, so a retry happens there. A font with no Silf table is now
also asked for it once per face instead of once per call.
Adds test_graphite2_failed_face_load_is_remembered, which counts Silf
table requests across three hb_shape() calls; it fails on the
unpatched tree (8 != 4) and passes with the fix.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-LPR3RSMJ.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Every shaper that returns true must leave the buffer with
have_positions set; the OpenType and fallback shapers call
clear_positions() unconditionally. _hb_graphite2_shape() borrows
pos[] as scratch via get_scratch_buffer(), which clears
have_positions, and the normal path restores it through
hb_buffer_get_glyph_positions(). But when Graphite deletes every
glyph of the run, the zero-slot early-out set buffer->len = 0 and
returned true without restoring the flag, so a later
hb_buffer_normalize_glyphs() (hb-shape --normalize-glyphs) hit
assert (buffer->have_positions) and aborted.
Restore the invariant where it is broken, by calling
buffer->clear_positions() in the empty-segment return.
Adds test_graphite2_all_glyphs_deleted, with an embedded 500-byte
font whose Silf rule deletes 'a'; shaping "aaa" must now succeed with
length 0 and positions, while the "aba" control is unchanged.
Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-BG9QJRVN.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
_hb_graphite2_shape() grows buffer->info with ensure() (a plain
realloc) and then fills each output glyph field by field, but never
assigned hb_glyph_info_t::mask. Entries beyond the original text
length therefore kept uninitialised heap bytes (or, in a reused
buffer, the mask from a previous shaping run); clear_glyph_flags()
only rewrites the low three bits, so hb_buffer_get_glyph_infos()
handed the stale bits 3-31 to the caller. Shaping output is correct
(every in-tree reader masks down to HB_GLYPH_FLAG_DEFINED), but
valgrind/MSan flag the uninitialised bytes and code reading the
private field sees values that vary run to run.
Set info->mask = 0 in the fill loop, next to the other fields. That
matches what hb_buffer_t::add() starts from and what the OpenType
shaper returns after hb_propagate_flags(), so the subsequent
clear_glyph_flags()/unsafe_to_break() operate on a defined value and
shaping output is unchanged. No other shaper needs the change.
Adds test_graphite2_inserted_glyph_masks, which first runs the
OpenType shaper so a removed default-ignorable leaves a non-zero mask
in the buffer storage, then checks that every glyph the Graphite
shaper adds for U+0622 comes back with nothing but glyph-flag bits.
Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-UDVJURW0.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The paint encoder memoizes a clip glyph's sub-blob, so layers painted
under the same clip stack cost it only a cached index and 24 bytes of
op stream each. The fragment shader, however, walks every curve of
every clip outline again for every layer in every fragment. Ops, clips
per layer and outline size each had a cap, but nothing bounded their
product: a small COLRv1 font nesting a few PaintGlyph clips of a dense
outline under tens of thousands of PaintSolid layers made the shader do
hundreds of millions of curve-loop iterations per fragment, a denial of
service on the GPU (or the CPU under a software rasterizer).
Charge each layer's reference to each clip sub-blob -- cached or freshly
encoded, glyph or path clip -- to the existing session work budget, in
encoded RGBA16I texels, which is what the shader's band walk scales
with. This lives in emit_all_clip_sub_blobs(), the one path all four
layer emitters go through; exhausting the budget marks the paint
unsupported like the other encoder limits, so hb_gpu_paint_encode()
returns NULL. It adds no new tunable: the budget defaults to
HB_BUDGET_GLYPH and hb_paint_set_budget(), including
HB_BUDGET_UNLIMITED, governs it as it does the outline work.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-FUCZJR1Y.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
hb_gpu_cubic_to_quadratics() split a cubic up to 10 levels deep
(2,047 nodes, each with a fit test) without charging that work to the
per-glyph budget and without checking whether the accumulator still
accepted output. Once the budget was spent, acc_emit() dropped every
curve but left g->success set, so each further cubic was fully
subdivided for nothing. A VARC composite of CFF glyphs that shares one
budget across many cubic-producing components could make a single
hb_gpu_draw_glyph() (or hb_gpu_paint_glyph() clip) call spend seconds
of CPU, far past the budget, as a CPU denial of service from a small
crafted font.
Charge one unit per node and return at the top of the recursion once
g->success is false or the budget is exhausted, the same approach the
raster flattener already takes. Returning is equivalent to emitting
here because acc_emit() discards everything once the budget is
negative, so the encoded outline is unchanged for any glyph that stays
within budget; the only cost is one extra unit per node, negligible
against HB_BUDGET_GLYPH.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-LZRUF6D2.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The GPU paint encoder left push_clip_rectangle at the no-op default
while pop_clip unconditionally decremented clip_depth. COLR emits a
rectangle push/pop pair around every PaintColrGlyph that has a ClipBox,
so that pop removed whatever glyph/path clip sat below it on the stack.
When such a PaintColrGlyph is nested inside a PaintGlyph, the sibling
layers encoded afterwards carried one clip outline too few, painting
ink outside the enclosing outline, or were dropped entirely when they
reached an emitter with clip_depth == 0.
Register a push_clip_rectangle callback that records the push in a
small per-depth counter (rect_clips[d] = rectangles pushed while
clip_depth was d). pop_clip consumes a non-zero count at the current
depth first and only otherwise pops a real clip. Rectangle clips are
still left unencoded, exactly as the v1 design notes state; the counter
only keeps the glyph/path clip depth balanced across the ignored pair.
This is correct for any LIFO push/pop order without allocation, and
changes nothing for paint trees without rectangle clips (the top-level
ClipBox in COLR::paint_glyph is already balanced).
Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-ZEL64M07.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
COLR::depend() walked the COLRv1 paint graph from scratch for every
BaseGlyphPaintRecord (clearing the visited set each time) with no total
work limit, so N base glyphs sharing one paint graph cost N times the
graph, quadratic in table size (204 s for a 200 KB font); the COLRv0
loop has the same base-glyphs x layers shape. The API is built only
with -Dexperimental_api=true.
hb_colrv1_depend_context_t, which already owns the per-walk depth and
visited-set guards, now also carries max_ops sized like the sanitizer's
(table length x HB_SANITIZE_MAX_OPS_FACTOR, clamped to the MIN/MAX),
charged one unit per Paint::dispatch(), per COLRv0 layer record, and per
PaintColrLayers layer run. Charging the layer run in dependv1() matters
because a layer resolving to the null or an unknown-format paint is
dropped by Paint::dispatch() before it reaches the context, so without
it a PaintColrLayers could still spin its 255-iteration loop uncharged.
Exhausting the budget calls depend_data->fail() (the existing error
idiom) so hb_subset_depend_from_face_or_fail() returns NULL rather than
a graph with silently missing edges, and the base-glyph loop stops once
the builder has failed.
The reproducer font is now rejected in a fraction of a second; the
control still succeeds, and legitimate fonts keep 64 ops per table byte
of headroom. Adds test_depend_colr_budget.
Follow-up to #6113.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-TO8ND880.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
hb_paint_sweep_gradient_tiles() documents that it iterates the 0..2π
sweep, and all three consumers (hb-cairo mesh patches, the SVG and PDF
writers) size their per-tile loops by tile width on that assumption.
Several emit sites (the start==end PAD case, the first PAD stop past 0,
and repeat/reflect segments straddling 0 or 2π) passed the angles
straight through, and COLRv1 variation deltas can place them hundreds of
thousands of radians outside the circle, so one tile could expand to
millions of patches: a 504-byte variable font drawn off its default
allocated ~1.6 GiB through hb-cairo.
#6157 bounded the number of sweep tiles; this bounds the width of each
one. Route every emit through a small clipping lambda inside the tiler
that clamps the tile to [0, 2π], lerps the end colours at the clip
points, and drops tiles entirely outside, so the contract holds at the
single place it is established rather than in each backend.
HB_PAINT_MAX_SWEEP_TILES and the repeat-loop bounds are untouched;
external callers need no change.
Adds a regression test calling the public function with far-out angles
for PAD/REPEAT/REFLECT; it fails without the fix.
Follow-up to #6157.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-GCNW3SND.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The COLRv1 paint walk bounds paint-table visits (HB_MAX_NESTING_LEVEL,
HB_MAX_GRAPH_EDGE_COUNT) but handed out ColorLine stops uncharged, so a
single 65535-stop ColorLine shared across up to 16384 gradient edges
could deliver ~10^9 stops from one hb_font_paint_glyph() call, keeping
the rendering thread busy for minutes per glyph in every backend.
Give hb_paint_context_t the session's live budget via
funcs->get_budget_remaining_ptr(), with the same local HB_BUDGET_GLYPH
fallback hb_draw_session_t uses, charge HB_BUDGET_16 per stop delivered
in ColorLine::get_color_stops() (the one place every consumer fetches
stops, so vector, raster, cairo and client paint functions are all
covered), and make recurse() skip further paints once the budget is
negative, as it already does for an oversized graph. The backend's one
budget is only spent, never re-armed, so this does not reintroduce the
cross-subsystem budget multiplication removed in #6147. hb-ft-colr.hh
has the same shape and gets the identical change.
With the default 2^24 budget about a million stops per session are
delivered before the rest of the walk is skipped best-effort. A
separate quadratic cost inside cairo's own gradient pattern building is
not addressed here. Adds a regression test that fails without the fix.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-F2NWHRVP.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
CID-keyed CFF charsets contain CIDs, not the standard SIDs needed by seac.
Interpreting the invalid operator can therefore retain unrelated glyphs
when their CIDs collide with the component SIDs from StandardEncoding.
Reject CID-keyed fonts in get_seac_components so both subset closure and
dependency collection skip these invalid lookups. Add a synthetic CID
font with colliding CIDs and check that only .notdef and the requested
glyph enter the subset plan.
The regression fails before the fix with four retained glyphs instead of
two. All 294 Meson tests pass, including the subset and API suites.
Assisted-by: OpenAI Codex
COLR::subset() gives every retained COLRv0 base glyph a private copy of
its layer range, so N base glyphs sharing L layers cost N x L layer
copies with two hash lookups each, and nothing checked the total against
the 16-bit numLayers header field. serialize_V0() walks the lazy
iterator twice and _hb_subset_table_try() retries while doubling the
buffer, so a ~200 KB font with all records naming the same range kept
hb-subset busy for about two minutes before failing.
Cap the summed layer count with a cheap walk over base_it before layer_it
is built, and drop COLR (return_trace (false)) when the total exceeds
0xFFFF, the same way this function already handles V0 records it cannot
subset; this also removes the 16-bit wrap in serialize_V0(). Any total
above 65535 could only have produced a failed subset or a wrapped,
invalid numLayers, so no valid output is lost.
The two V0 closure helpers had the same N x L shape during planning;
collect the layer indices of all retained base glyphs into one set first
and visit each layer once. closure_glyphs() now takes the glyph set in
one call (the accelerator wrapper changes signature with it; no public
API change), and _colr_closure() passes the whole set instead of looping.
Adds test_subset_colr_shared_layers (256 base glyphs all claiming the
same 256 layers): retaining 255 gives a 65280-layer table, retaining all
256 gives an empty COLR.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-4T7NHCTK.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
PaintColrLayers::closurev1() recorded firstLayerIndex ..
firstLayerIndex + numLayers - 1 as retained layers without checking
the range against LayerList.len (PaintColrLayers::sanitize is a plain
check_struct), and _colr_closure() then creates one colrv1_layers map
entry per retained index. A crafted font whose leaf paints point past
the end of the LayerList could therefore add up to 255 entries each for
layers that do not exist, driving subset-plan memory to roughly 1200x
the font size (585 MiB for a 512 KB font).
Clamp the range to the LayerList at the one place the retained-layer set
is built, before add_layer_indices() and for the dispatch loop alike;
this also removes the firstLayerIndex + numLayers wrap-around in the loop
bound. Readers (paint_glyph, dependv1) never record indices and already
tolerate out-of-range ones via LayerList::get_paint() returning Null, so
they are left alone. A PaintColrLayers whose range lies past the source
LayerList now has no mapping and subset writes 0xFFFFFFFF; both that and
a renumbered index past the new LayerList are out of range and draw
nothing.
Adds a regression test that builds such a font inline and pins the
output; it fails without the fix.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-ROQFK0RA.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
_hb_face_builder_get_table_tags() copied every key out of the hash map
and qsort()ed it on each call, so a caller paging through the list (the
subsetter uses 32-entry pages in hb_subset_plan_execute_or_fail() and
_is_table_present()) paid N/32 sorts of N tags per enumeration. With
the 65535-table face that hb_subset_preprocess() hands back this was
~25 s of CPU per hb_subset_or_fail() call.
Keep an hb_vector_t<hb_tag_t> next to the map and maintain it in
hb_face_builder_add_table(), the only place keys are inserted: a binary
search finds the slot, the vector is pre-allocated before the map is
touched so an allocation failure leaves both structures unchanged, and
the slot is opened with the same resize+memmove idiom hb-bit-set.hh
uses. The getter becomes a sub_array() copy, so enumeration is O(page)
and the returned order is unchanged. _hb_face_builder_data_reference_blob()
keeps its own sort, which orders by blob size, not by tag.
A regression test adds tags out of order, one of them twice, and checks
that paging with a 4-entry array returns each tag once in ascending
order.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-VENZFNXH.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
A builder face must always be serializable into an sfnt, but
hb_face_builder_add_table() accepted any number of tables while the
table directory's numTables is 16-bit. Serializing a 65536th table hit
the assert in BinSearchHeader::operator= (or, with NDEBUG, truncated the
count and then looped forever through hb_face_reference_blob()'s retry).
The subsetter reaches this with HB_SUBSET_FLAGS_PASSTHROUGH_UNRECOGNIZED
because glyf::subset() always adds a 'loca' the source need not have.
Enforce the limit where tables are added, so the subsetter fails cleanly
at plan->add_table() and a builder face can always be written out;
replacing an existing tag is still allowed. Also stop
hb_face_reference_blob() from recursing into itself on the fallback
builder it just built (serialize it directly with reference_table()):
otherwise a builder that cannot produce a blob is retried without end.
A regression test in test/api/test-get-table-tags.c adds 65535 tags,
checks the 65536th is refused, that replacement still works, and that
the serialized blob has the expected size.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-7BXQZ7HS.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
name_table_overrides stores hb_malloc()ed strings as plain hb_bytes_t
values, so the invariant that every stored string is freed exactly once
in ~hb_subset_input_t broke when set() silently overwrote an existing
key: overriding the same name record more than once on one input leaked
the previous copy, and so did a NULL (remove) after a non-empty
override.
hb_subset_input_override_name_table() is the only place that allocates
these strings, so fix it there: look the record up with has(&old) and
fini() it in place before set() (fini nulls the pair, so no path frees
twice, and the lookup happens before set() can reallocate the table).
Also free the fresh copy and return false when set() cannot store it,
instead of leaking it and returning true. hb_subset_plan_t copies the
map and frees its own copies, so it is unaffected. No public API/ABI
change.
A regression line in test_subset_name_overrides overrides one record
twice; only the last string survives and the first must not leak.
Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-8SA3SRW4.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The function documents len as the length of str, but located the ':'
separators with strpbrk() and matched "drop" with strcmp(), both of
which scan to the next NUL byte. A caller passing an exact-length,
non-NUL-terminated slice therefore got an out-of-bounds read, and bytes
beyond len could change or reject the parsed range.
Bound every scan by str+len: each strpbrk() becomes memchr() bounded by
end, the strcmp() becomes a len==4 && hb_memcmp() check, and the empty
-piece test !*str becomes str == end. This is the same discipline the
sibling parsers hb_feature_from_string()/hb_variation_from_string()
already follow. For len == -1 (the only in-tree caller) len becomes
strlen() first, so behaviour is unchanged. No public API/ABI change.
A regression test in test/api/test-subset.c passes prefixes of longer
literals with an explicit len and checks the NUL-terminated cases still
parse as before.
Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-IL9ZX304.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [cairo] Paint nested color glyphs inline to bound recursion
hb_cairo_paint_color_glyph() accepted the color_glyph paint callback
and drew the nested glyph with cairo_show_glyphs(), which re-enters
hb_font_paint_glyph() through a new cairo scaled font with a fresh
hb_paint_context_t. The glyph decycler, HB_MAX_NESTING_LEVEL and the
edge budget therefore start over at every level, so two glyphs that
paint each other with PaintColrGlyph recurse until the stack is
exhausted. The per-scaled-font hb_cairo_budget_t cannot bound this
either: the nested glyph is shown through a different scaled font, so
each level gets its own budget.
Decline the callback, returning false exactly as hb-raster's does, so
the COLR (and hb-ft-colr) walk paints the nested glyph inline under the
decycler and depth limits of the walk already in progress.
A regression test with two PaintColrGlyph glyphs that paint each other
is added to test/api/test-cairo.c; it aborts on the unpatched library
and passes with the fix.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-VPKA505E.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [cairo] Don't leak the hb_font_t created per scaled font
hb_cairo_init_scaled_font() must hand exactly one reference of the
hb_font_t to the cairo_scaled_font_t. For a face-based font face
(hb_cairo_font_face_create_for_face()) it creates the font with a
reference count of 1, but then still called hb_font_reference() before
attaching it, so the creating reference was never released. Every
finalized scaled font therefore leaked an hb_font_t, pinning its
hb_face_t, the font blob and the accelerators until the process exits.
Cairo finalizes scaled fonts during normal operation once its cache
fills, so the leak accumulates as content selects distinct sizes,
transforms or font options.
Take the extra reference only in the branch where the font is the
shared one owned by the cairo font face (the font-based constructor),
and transfer the freshly created font as-is. The set_user_data result
is now checked and the font released on failure, matching the
budget/color-cache idiom a few lines below and the font-face
constructors in the same file.
A callback installed with hb_cairo_font_face_set_font_init_func() that
returns a different font keeps its historical behavior: the returned
font is referenced rather than assumed to transfer ownership, so no
in-tree contract changes and no caller can turn into a use-after-free.
hb-view uses the font-based constructor and was unaffected.
A regression test in test/api/test-cairo.c registers a face destroy
notifier, draws through a face-based font face, flushes cairo's
scaled-font cache and asserts the face was destroyed; it fails on the
unpatched library and passes with the fix.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-BAUN9JN4.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [cairo] Map non-monotone buffer clusters to one cairo cluster
hb_cairo_glyphs_from_buffer() asserted that buffer clusters are monotone
in the buffer direction, but hb_shape() does not guarantee that:
HB_BUFFER_CLUSTER_LEVEL_CHARACTERS, shaping that hits the ops limit
mid-lookup, and Indic reordering corner cases can all produce
non-monotone clusters. The function runs from HarfBuzz's own cairo
text_to_glyphs callback on attacker-controlled text and fonts, so the
assertion was an input-dependent abort (and, with NDEBUG, an unchecked
backward walk off the ends of the utf8 buffer).
The cluster-counting loop that already walks the buffer now detects a
step against the buffer's direction and falls back to a single cairo
cluster mapping all of the utf8 to all of the glyphs, which cairo
accepts. The monotonicity assertions in the fill step then hold by
construction and glyph output is unchanged for monotone buffers.
A regression test in test/api/test-cairo.c feeds monotone and
non-monotone LTR/RTL buffers through both cluster modes and checks the
cluster counts and byte/glyph totals; it aborts on the pristine tree.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-T4PZ1H72.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* [cairo] Charge compositing operations to the glyph budget
hb-cairo's per-glyph work budget was spent only on emitted path segments,
so a COLRv1 font could pay once for a clip outline (push_clip_glyph) and
then have cairo re-rasterize it for every PaintSolid/gradient/group
composite under it, up to the COLR edge limit. That is the
multiplication of limits the shared budget in hb-limits.hh exists to
prevent: a 2 KB font kept hb-view busy for over a minute on one glyph.
Charge every composite in the cairo backend, where the cost is incurred
and where the sibling backends already charge per operation (hb-raster
charges pixel area per paint). hb_cairo_context_t now counts the
segments of the current path and keeps a stack of the clip paths in
force, maintained by the push_clip_* callbacks and pop_clip; spend_paint()
charges every fill, paint, group and gradient with (1 + segments) times a
per-source weight, squared when more than one path is in force since
cairo then intersects the paths per operation. These segment and clip
counts are inputs to the existing budget_remaining counter; they are not
a separate per-callback limit. The weights (HB_BUDGET_512 for
solid/group, 1024 for linear/radial gradients, a new HB_BUDGET_8192 for
the sweep mesh pattern) follow per-composite timings measured on
cairo 1.18.
Nested color glyphs are already painted inline by the color_glyph
callback, so their composites are charged against the clips in force at
that point; no change is needed there.
Behaviour change: a glyph whose composites exceed the budget (about 32k
segment-composites, roughly a second of cairo time at hb-view's default
size) is truncated best-effort, as outline work already is. All glyphs
of the COLRv1 glyf (static and variable) and CFF2 test fonts render
byte-identically through hb-view with and without this change.
A regression test with a generated 3 KB font is added to
test/api/test-cairo.c alongside its fontTools generator; it finishes in
about a second once the paints are charged and guards against
reintroduction through the meson test timeout rather than a
discriminating assertion.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-38OVH0N4.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
The work budget (max_ops) is meant to bound every buffer pass whose
length the font or text controls, but the same-cluster walks that
re-merge a neighbouring run were never charged:
- the backward merge in delete_glyph() (reached from an empty
MultipleSubst Sequence);
- its copy in delete_glyphs_inplace() (default-ignorable / AAT
glyph deletion);
- the "extend" and cross-buffer continuation loops in
merge_clusters_impl() / merge_out_clusters_impl() (reached from
the Thai/Lao shaper, the normalizer, morx ligatures, and any
ligature/multiple substitution).
Once one long same-cluster run exists, every further merge or
deletion next to it walks the whole run again, so a single hb_shape()
call does O(N^2) work the budget never sees: e.g. U+0E01 followed by
130,000 x U+0E33 takes ~21 s.
Charge the glyphs actually walked to max_ops and fail the buffer when
the budget is gone, following shift_forward()/move_to(), and skip the
walk once the buffer has failed (delete_glyphs_inplace() and the
shaper-level merge_clusters() callers keep calling after a failure).
merge_out_clusters_impl() also gains the "cluster != ..." guards that
merge_clusters_impl() already had, so it no longer walks a run that
already holds the merged value; set_cluster() is a no-op on such a
glyph, so output is unchanged. Verified: default-direction Thai
output is byte-identical to before at sizes that fit the budget, and
pathological inputs now end with hb_buffer_allocation_successful() ==
false, like any other max_ops exhaustion.
Regression test added to test/api/test-shape.c using a stock font.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-CQ04GDSH.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Every hb_buffer_set_*() is meant to be a no-op on an immutable
buffer, which is what keeps the static _hb_Null_hb_buffer_t
(returned by hb_buffer_get_empty(), and by hb_buffer_create() on
allocation failure) inert. Three entry points skipped that guard:
- hb_buffer_set_not_found_variation_selector_glyph() stored into
the singleton;
- hb_buffer_guess_segment_properties() wrote direction and
language into it;
- hb_buffer_create_similar() called similar() on the singleton
when its internal hb_buffer_create() failed, copying the source
buffer's settings onto the shared empty buffer and leaking a
reference to its unicode funcs.
Add the same hb_object_is_immutable() early return the sibling
setters use, and guard the create_similar() allocation-failure path
the way hb_font_create_sub_font() already does. No other public
setter in hb-buffer.cc lacks the check. No API/ABI change; the
only behaviour change is that these calls on the empty buffer now
do nothing, as the documented object model promises.
A regression check is appended to test_buffer_empty().
Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-RNK5DQFY.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
IndexSubtableArray::find_table() finds a glyph's bitmap by walking
the strike's whole IndexSubtableRecord array. The record count is a
32-bit field bounded only by the table length, and the walk is
charged to no work limit, so two callers run it once per glyph and
turn font size times text/glyph count into CPU time:
- hb-ot-font, on every extents/PNG/paint query, which stalls
hb_shape() (vertical text without VORG/vmtx measures each glyph by
its extents) and the extents/paint/PNG getters;
- the subsetter, for every output glyph of every strike in
IndexSubtableArray::build_lookup().
With a ~320 KB font one vertical hb_shape() of 2000 letters took ~31 s
against ~0.25 s for the same font with the record count set to 1, and
a ~303 KB font kept hb-subset --gids='*' busy for ~100 s.
build_lookup() now maps each retained glyph to the first record that
covers it in one pass over the records (a copy of the glyphset with
del_range() after each record keeps the first-covering-record rule),
instead of searching the array per glyph. Output is byte-identical.
The accelerator builds a bounded per-face index: for the first strike
of each ppem it records the disjoint (ppem, glyph range) -> record
index spans in a sorted vector that find_table() binary searches,
preserving the first-covering-record rule exactly. The index is
capped at HB_CBDT_MAX_INDEX_ENTRIES (a new limit in hb-limits.hh): a
strike whose records would overflow it, or that hits an allocation
failure, falls back to the original linear walk via walk_ppems, so
the index never exceeds the cap no matter how many records the
sanitizer accepted. BitmapSizeTable::find_table() is kept as that
fallback.
Known limitation: the cap is one shared budget, filled in sizeTables
order. A single ~512 KB filler strike of ~65535 one-glyph records
exhausts it, so every strike after it in the array keeps the full
per-glyph walk; a font under 3x the reproducer's size can still force
that walk for those later strikes. This is acceptable for a
non-security performance bug and keeps lookup results exact for every
font. Per-strike lazy indexing (build a strike's index on first use,
under its own cap) is the real follow-up and is left out here to keep
the change small.
Lookups are unchanged. The reproducer drops from ~31 s to ~0.39 s
with identical shaped output; the 303 KB subsetter case drops to
~0.07 s; the 197 MiB worst case (255 strikes at distinct ppems
sharing one 65535-record array) now peaks at ~18 MiB. Adds
test_hb_ot_color_png_cbdt_records (pins the first-covering-record
rule through the index) and test_subset_cbdt_many_records (a
65535-glyph, 64-strike, keep-everything subset that must finish
quickly). The full test suite passes; ASan/UBSan clean.
Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-YJXG98O5.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The draw encoder returns the empty blob for outlines without curves.
Treating it as a clip sub-blob leaves a layer referring to the next
payload or the end of the encoded data. Cache empty glyph and path
clips separately and skip their consuming layers. Preserve the
paint encoder's no-ink contract when only group operations remain,
returning an empty blob with zero extents.
Use fallible blob creation for gradient payloads so allocation failure
cannot produce the same zero-length sub-blob references.
Add an API regression using an ordinary font and paint callbacks,
covering solid and gradient layers, empty paths, groups, and clip slot
reuse. Validate the surviving layer's outline and band references.
The regression fails on the original encoder; the full Meson suite
passes (274 tests).
Reported by Anthropic's OSS Scanner as ANT-2026-5Z1FLVCW.
Assisted-by: OpenAI Codex
hb_pair() preserves references to lvalue arguments. The alternate
collection callbacks returned pairs referencing their own by-value
parameters, so the next iterator stage read them after the call ended.
Pass each AlternateSubst glyph directly to the collector helper, which
already encodes its alternate index. This also keeps alternate_count
keyed by the original glyph. Return a value pair for SingleSubst format
1, as the subsetting path already does.
Cross-check collected maps against the per-glyph getter for four
SourceSansPro lookups. The alternate and both SingleSubst format 1
cases fail on the previous code; the format 2 control passes.
Testing: meson test -C build (292 passed; check-symbols skipped on
macOS). All five alternate API tests also pass under ASan and UBSan,
with stack-use-after-return detection enabled.
Discovered by Anthropic's OSS Scanner, as vulnerability
ANT-2026-N7S3EYU4.
Assisted-by: OpenAI Codex
The glyph slot belongs to the shared FreeType face. Copy its bitmap
and dimensions before releasing the face lock, then query extents
and invoke the image callback without the lock. Fail if the bitmap
copy cannot be allocated.
Add a bounded shared-font paint regression using the existing emoji
fixture. Check BGRA blob dimensions and reenter the font from the
image callback. The test crashes before the fix and passes after it.
The full Meson suite passes (274 tests).
Reported by Anthropic's OSS Scanner as ANT-2026-ANVKHBVD.
Assisted-by: OpenAI Codex
Check ensure(glyph_count) before writing Graphite output. Release the
feature values and segment and return failure when buffer growth fails.
Add a small synthetic font and a bounded regression that refuses buffer
growth via max_len. The normal path produces 164 glyphs; the failure path
retains the original input length and reports allocation failure. Include
the font generator, whose output matches the checked-in fixture.
The new regression fails before the fix under ASan and passes afterward.
All 276 tests pass with Graphite2 enabled; the regression also passes under
ASan and UBSan.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-HEQW39B7.
Assisted-by: OpenAI Codex
hb-cairo's per-glyph work budget was spent only on emitted path segments,
so a COLRv1 font could pay once for a clip outline (push_clip_glyph) and
then have cairo re-rasterize it for every PaintSolid/gradient/group
composite under it, up to the COLR edge limit. That is the
multiplication of limits the shared budget in hb-limits.hh exists to
prevent: a 2 KB font kept hb-view busy for over a minute on one glyph.
Charge every composite in the cairo backend, where the cost is incurred
and where the sibling backends already charge per operation (hb-raster
charges pixel area per paint). hb_cairo_context_t now counts the
segments of the current path and keeps a stack of the clip paths in
force, maintained by the push_clip_* callbacks and pop_clip; spend_paint()
charges every fill, paint, group and gradient with (1 + segments) times a
per-source weight, squared when more than one path is in force since
cairo then intersects the paths per operation. These segment and clip
counts are inputs to the existing budget_remaining counter; they are not
a separate per-callback limit. The weights (HB_BUDGET_512 for
solid/group, 1024 for linear/radial gradients, a new HB_BUDGET_8192 for
the sweep mesh pattern) follow per-composite timings measured on
cairo 1.18.
Nested color glyphs are already painted inline by the color_glyph
callback, so their composites are charged against the clips in force at
that point; no change is needed there.
Behaviour change: a glyph whose composites exceed the budget (about 32k
segment-composites, roughly a second of cairo time at hb-view's default
size) is truncated best-effort, as outline work already is. All glyphs
of the COLRv1 glyf (static and variable) and CFF2 test fonts render
byte-identically through hb-view with and without this change.
A regression test with a generated 3 KB font is added to
test/api/test-cairo.c alongside its fontTools generator; it finishes in
about a second once the paints are charged and guards against
reintroduction through the meson test timeout rather than a
discriminating assertion.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-38OVH0N4.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Release the face lock around solid, gradient, and custom palette
callbacks. Keep lazy FreeType color-stop reads locked and give each
getter call its own iterator, so callbacks can query the same font
without deadlocking or disturbing another stop query.
Snapshot the selected palette once per COLRv1 traversal, shared by
the bounds and paint passes. Nested paints can select a different
palette on the face; they must not change the outer paint's colors.
Return failure if the palette copy cannot be allocated. Stops remain
lazy and no cache policy or limits change.
Add a bounded callback regression with the existing COLRv1 fixture.
It queries font extents, performs nested paints with another palette,
and checks repeated and paged stop reads against the OT backend.
The original code times out; unlocking without copying the palette
fails the color comparison. The full Meson suite passes: 274 tests, no failures.
Reported by Anthropic's OSS Scanner as ANT-2026-YPLDSFHA.
Assisted-by: OpenAI Codex
IndexSubtableRecord::add_new_subtable() bounds-checks each retained
glyph's image block against the source CBDT table, but nothing
requires the blocks of different glyphs (or strikes) to be distinct
and nothing limits the total copied. A format 3 offsetArray of
0, 65535, 0, 65535, ... makes every even glyph copy the same 64 KB,
so a ~186 KB font makes one hb_subset_or_fail() peak at ~3.8 GB and
emit a ~1.97 GB font. The existing source_blob->length * 256 cap
covers only the serializer buffer holding the new CBLC, not the CBDT
side buffers.
Charge every block copied out of the source CBDT to a byte budget
that is proportional to the source table and shared across strikes,
and fail the strike when it runs out; the existing subset_size_table()
path then reverts that strike and continues. The budget lives in
cbdt_dedup_context_t, which CBLC::subset already shares across every
strike, and is set to cbdt_length * HB_SUBSET_CBDT_MAX_COPY_FACTOR, a
new limit (64) in hb-limits.hh. The charge is taken before the copy
into the per-strike buffer, so strikes that end up sharing data are
bounded as well, and it covers index formats 1/2/3 and overlapping
records, not only non-monotonic format 3 arrays. The budget defaults
to unlimited, so the direct users of the struct (test-cbdt-cache) are
unaffected; a well-formed font copies each byte at most once per
strike, so only a font whose strikes reference the table more than 64
times over loses bitmaps.
This is distinct from the integer-overflow hardening of
_copy_data_to_cbdt() in PR #6485: that bounds the final append to
cbdt_prime, this bounds the overlap amplification before the copy.
Adds test_subset_cbdt_overlapping_images, which builds the format 3
shape above and asserts the output CBDT stays within the factor
(524292 > 65536 on the unpatched tree). The api and subset suites
pass and the reproducer drops from 3767 MiB to 17 MiB.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-C39OXNU0.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Keep the memory-backed FT_Face blob on the hb_face_t even when the
OpenType sanitizer discards its copy. Otherwise the destroy callback
can release the FT_Face while the face or font still uses it. Return
the empty object on allocation failure before accessing that pointer.
Keep a blob loader's input bytes on the FT_Face rather than the
hb_face_t, since retained table blobs can outlive the latter. Keep the
library reference on the input blob and release it outside the static
FreeType mutex. Initialize file-loader ownership before transferring
references as well.
Add regressions for destroy-callback timing, referenced font lifetime,
and table blobs retained past the source face. All 293 tests pass,
including all eight FreeType subtests under ASan and UBSan. A separate
sanitized ownership probe passes 154 allocation-failure cases.
Discovered by Anthropic's OSS Scanner, as vulnerabilities
ANT-2026-FC0F75Y2 and ANT-2026-O2E5WAA5.
Assisted-by: OpenAI Codex
hb_cairo_glyphs_from_buffer() asserted that buffer clusters are monotone
in the buffer direction, but hb_shape() does not guarantee that:
HB_BUFFER_CLUSTER_LEVEL_CHARACTERS, shaping that hits the ops limit
mid-lookup, and Indic reordering corner cases can all produce
non-monotone clusters. The function runs from HarfBuzz's own cairo
text_to_glyphs callback on attacker-controlled text and fonts, so the
assertion was an input-dependent abort (and, with NDEBUG, an unchecked
backward walk off the ends of the utf8 buffer).
The cluster-counting loop that already walks the buffer now detects a
step against the buffer's direction and falls back to a single cairo
cluster mapping all of the utf8 to all of the glyphs, which cairo
accepts. The monotonicity assertions in the fill step then hold by
construction and glyph output is unchanged for monotone buffers.
A regression test in test/api/test-cairo.c feeds monotone and
non-monotone LTR/RTL buffers through both cluster modes and checks the
cluster counts and byte/glyph totals; it aborts on the pristine tree.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-T4PZ1H72.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
hb_cairo_init_scaled_font() must hand exactly one reference of the
hb_font_t to the cairo_scaled_font_t. For a face-based font face
(hb_cairo_font_face_create_for_face()) it creates the font with a
reference count of 1, but then still called hb_font_reference() before
attaching it, so the creating reference was never released. Every
finalized scaled font therefore leaked an hb_font_t, pinning its
hb_face_t, the font blob and the accelerators until the process exits.
Cairo finalizes scaled fonts during normal operation once its cache
fills, so the leak accumulates as content selects distinct sizes,
transforms or font options.
Take the extra reference only in the branch where the font is the
shared one owned by the cairo font face (the font-based constructor),
and transfer the freshly created font as-is. The set_user_data result
is now checked and the font released on failure, matching the
budget/color-cache idiom a few lines below and the font-face
constructors in the same file.
A callback installed with hb_cairo_font_face_set_font_init_func() that
returns a different font keeps its historical behavior: the returned
font is referenced rather than assumed to transfer ownership, so no
in-tree contract changes and no caller can turn into a use-after-free.
hb-view uses the font-based constructor and was unaffected.
A regression test in test/api/test-cairo.c registers a face destroy
notifier, draws through a face-based font face, flushes cairo's
scaled-font cache and asserts the face was destroyed; it fails on the
unpatched library and passes with the fix.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-BAUN9JN4.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
hb_cairo_paint_color_glyph() accepted the color_glyph paint callback
and drew the nested glyph with cairo_show_glyphs(), which re-enters
hb_font_paint_glyph() through a new cairo scaled font with a fresh
hb_paint_context_t. The glyph decycler, HB_MAX_NESTING_LEVEL and the
edge budget therefore start over at every level, so two glyphs that
paint each other with PaintColrGlyph recurse until the stack is
exhausted. The per-scaled-font hb_cairo_budget_t cannot bound this
either: the nested glyph is shown through a different scaled font, so
each level gets its own budget.
Decline the callback, returning false exactly as hb-raster's does, so
the COLR (and hb-ft-colr) walk paints the nested glyph inline under the
decycler and depth limits of the walk already in progress.
A regression test with two PaintColrGlyph glyphs that paint each other
is added to test/api/test-cairo.c; it aborts on the unpatched library
and passes with the fix.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-VPKA505E.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Glyph zero is always reserved for .notdef. Reject mappings that assign
another retained glyph to it, so the output list has one entry per id.
Also bound the resulting glyph count by the widest supported count
field, MAXP's HBUINT24. Account for the unmapped glyphs and the initial
slot before assigning ids, avoiding wraparound and oversized counts in
table subsetters. The limit applies to the count, not the highest id.
Document these constraints and test valid renumbering, gaps, ignored
remapping of .notdef, reserved-id collisions, and out-of-range counts.
The regression and stock hb-subset both reproduce the issue under ASan
before the fix. All 293 tests pass after it, including the subset suite;
the API subset tests and command-line checks also pass ASan and UBSan.
Discovered by Anthropic's OSS Scanner, as vulnerability
ANT-2026-6I1RIFMQ.
Assisted-by: OpenAI Codex
A custom glyph mapping can leave unassigned output glyph IDs beyond
the source glyph count. The preprocessing glyph-to-SID map only covers
source glyphs, so use the existing charset lookup for those gaps and
skip the map-based range shortcut there.
Compare plain and preprocessed subsets of existing name-keyed and
CID-keyed fonts with output gaps. The new regression fails under ASan
before the fix. The complete ASan/UBSan Meson suite passes afterward
(293 tests, including 23 CFF1 API subtests).
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-42ZOI3TR.
Assisted-by: OpenAI Codex
The graph total is size_t, while the output vector allocation takes an
unsigned int. Check the total against the blob length limit before that
conversion, so the allocation and serialization context use the same
size. Totals above INT_MAX cannot produce a valid output blob anyway.
Add a public-API regression whose objects share their backing storage,
keeping its memory use small while exercising a large graph total.
Testing: meson test -C build (292 passed; check-symbols skipped on
macOS), plus test-subset-repacker with ASan and UBSan. The regression
reproduces the invalid write without the check and fails cleanly with it.
Discovered by Anthropic's OSS Scanner, as vulnerability
ANT-2026-4Q0YO46E.
Assisted-by: OpenAI Codex
The baseline fallback accepts an OpenType script tag but compared it
with hb_script_t values. Convert the tag before choosing the glyph
used to synthesize the hanging baseline.
Exercise Bengali's old and new OpenType tags, Tibetan, and the script
and language entry point. The updated test fails before the fix
(622 versus 600); the full Meson suite passes (293 tests).
Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-COIT72UF.
Assisted-by: OpenAI Codex
The point-in-quad test rejected the interior side of each edge for
both winding orders. Reverse the comparisons for rectangle and mask
intersections, and clarify how the edge normal depends on winding.
Add a regression for skew, reflected skew, and rotation, with one or
two nested rectangle clips to exercise both intersection paths. The
center pixel was transparent before the fix. The full Meson suite
passes (293 tests).
Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-AM92X98M.
Assisted-by: OpenAI Codex
Fonts without vhea returned the ascender for the vertical descender
metric. Read the descender from the synthesized vertical font extents,
as the horizontal fallback already does.
Add a regression comparing all three fallback vertical metrics with
the font extents. It fails before this change (1024 versus -1024).
The full Meson suite passes (293 tests).
Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-4UNO2SK8.
Assisted-by: OpenAI Codex