The support scalar is 1 (not 0) at v == peak, so a tent whose peak sits
exactly on the reachable-range boundary is live there. The ranges'
one-unit padding at their producer already prevented wrong culling in
practice; strictness makes the predicate correct on its own terms.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The estimator that picks between offset-compensation knot sets (and
decides whether to warn) sampled a uniform 257-point grid only, which
can miss the worst kink in precisely the steep-segment regime it
targets. Augment the sample set with the user-space preimages of every
kink of the residual: old and new avar v1 breakpoints and the offset(z)
knots, pulled back through the inverse of the instantiated mapping.
The pointwise F2Dot14 rounding keeps this an estimate, but every
piecewise-linear extremum is now visited.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.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
* [paint] Bound sweep-gradient tile emission
hb_paint_sweep_gradient_tiles() walked to the first repeat that can
reach angle 0 by subtracting the color-line span one repeat at a
time, and bounded the repeat loop only by an absolute repeat index
of 1000. A repeat/reflect color line whose stops span a tiny angle
then emits repeats-times-stops patches: the ClusterFuzz font drives
27648 stops over ~0.0008 rad, producing ~140M emit_patch callbacks
and gigabytes of Coons-patch mesh in the PDF vector backend, and a
libFuzzer timeout. The one-span-at-a-time walk could also fail to
terminate outright for angle values reachable through variation
deltas, once the span drops below the float ulp of the angle.
Cap emitted tiles at the new HB_PAINT_MAX_SWEEP_TILES (4096); its
inverse doubles as the angular resolution of the tiling, 2π/4096.
A color line whose period is below that resolution repeats faster
than the tiles can resolve, so instead of tiling it, fill the whole
circle flat with the width-weighted average color of one period --
the band-limit of the pattern. Compute the starting repeat directly
by division, bailing out on non-finite angles, and guard the inner
loop against clipped-segment spins that unsorted (contract-violating)
stop arrays could otherwise drive. The absolute-index 1000 cap is
gone: repeat gradients that legitimately need more repeats to cover
the full circle now render completely instead of being silently
truncated. The helper is also used by the hb-cairo glue, which
picks up the same bounds.
The ClusterFuzz reproducer drops from 27s / 7.8GB RSS locally to
under 0.01s / 8MB, each degenerate gradient collapsing to one flat
patch. All 96 sweep glyphs of test_glyphs-glyf_colr_1.ttf and 98
sweep glyphs of its variable version at three variation settings
render byte-identically in both SVG and PDF; full test suite passes.
https://oss-fuzz.com/testcase-detail/6490910482038784
Assisted-by: Claude Fable 5 <noreply@anthropic.com>
* [vector] Charge sweep-gradient patches to the paint work budget
The SVG and PDF vector paint backends charge glyph-outline bytes to
the session work budget, but sweep-gradient patch emission appended
mesh/path bytes with no charge. Even with the per-call tile cap
from the previous commit, a COLR paint graph can invoke many sweep
gradients, multiplying the per-gradient patch data by the
paint-graph traversal limits.
Charge the bytes appended by each emitted patch to the session
budget and skip patch generation once the budget is spent, matching
the existing outline-extraction pattern.
Sweep glyphs of test_glyphs-glyf_colr_1.ttf and its variable
version render byte-identically in both SVG and PDF; full test
suite passes.
Assisted-by: Claude Fable 5 <noreply@anthropic.com>
* [test] Add fuzz seed for sweep-gradient tile timeout
The font drives two sweep gradients with 27648 color stops over an
angular span of ~0.0008 rad with a repeat extend, previously
emitting ~140M Coons patches in the PDF vector backend and timing
out on ClusterFuzz before the preceding two commits.
https://oss-fuzz.com/testcase-detail/6490910482038784
Assisted-by: Claude Fable 5 <noreply@anthropic.com>
Under the fuzzer's failing-malloc allocator, the font drives a COLR
paint graph whose session initialization fails its stack push and
then re-cleared a 4096x4096 root surface on every one of ~2240
paint callbacks, timing out on ClusterFuzz before the previous
commit.
https://oss-fuzz.com/testcase-detail/4604877465255936
Assisted-by: Claude Fable 5 <noreply@anthropic.com>
ensure_initialized() lazily acquires the session's root surface on
the first paint callback. When one of its stack pushes fails under
OOM, the hb_vector_t goes into its sticky error state and the push
can never succeed again -- but every subsequent paint callback
re-ran the whole initialization: acquire_surface(), configure, and
a full-surface clear, then failed the push and released the surface
again. Nothing along that path charges the session work budget, so
a COLR paint graph with thousands of callbacks re-paid a 4096x4096
(64MB) memset each time: the ClusterFuzz font drives ~2240 fill
callbacks, ~140GB of memset, and a libFuzzer timeout. Simulating
the failed push locally (forcing the stack's error state in gdb)
reproduces it: 15664 full-surface clears, 70s.
Bail out of initialization if either stack is in error, and charge
the root surface's area to the session budget before acquiring it,
mirroring the push_group() pattern, so any other repeated-
initialization path drains the budget instead of spinning.
Successful initialization re-arms the budget right after, so the
charge is a no-op for normal sessions.
Also drop a stray transform_stack.pop() from the clip-push failure
path: ensure_initialized() never pushes a transform, so the pop
could strip a transform legitimately pushed by an earlier callback.
With the error state forced, the reproducer now performs 2 clears
and finishes instantly; full test suite passes.
https://oss-fuzz.com/testcase-detail/4604877465255936
Assisted-by: Claude Fable 5 <noreply@anthropic.com>
The font drives two sweep gradients with 27648 color stops over an
angular span of ~0.0008 rad with a repeat extend, previously
emitting ~140M Coons patches in the PDF vector backend and timing
out on ClusterFuzz before the preceding two commits.
https://oss-fuzz.com/testcase-detail/6490910482038784
Assisted-by: Claude Fable 5 <noreply@anthropic.com>
The SVG and PDF vector paint backends charge glyph-outline bytes to
the session work budget, but sweep-gradient patch emission appended
mesh/path bytes with no charge. Even with the per-call tile cap
from the previous commit, a COLR paint graph can invoke many sweep
gradients, multiplying the per-gradient patch data by the
paint-graph traversal limits.
Charge the bytes appended by each emitted patch to the session
budget and skip patch generation once the budget is spent, matching
the existing outline-extraction pattern.
Sweep glyphs of test_glyphs-glyf_colr_1.ttf and its variable
version render byte-identically in both SVG and PDF; full test
suite passes.
Assisted-by: Claude Fable 5 <noreply@anthropic.com>
hb_paint_sweep_gradient_tiles() walked to the first repeat that can
reach angle 0 by subtracting the color-line span one repeat at a
time, and bounded the repeat loop only by an absolute repeat index
of 1000. A repeat/reflect color line whose stops span a tiny angle
then emits repeats-times-stops patches: the ClusterFuzz font drives
27648 stops over ~0.0008 rad, producing ~140M emit_patch callbacks
and gigabytes of Coons-patch mesh in the PDF vector backend, and a
libFuzzer timeout. The one-span-at-a-time walk could also fail to
terminate outright for angle values reachable through variation
deltas, once the span drops below the float ulp of the angle.
Cap emitted tiles at the new HB_PAINT_MAX_SWEEP_TILES (4096); its
inverse doubles as the angular resolution of the tiling, 2π/4096.
A color line whose period is below that resolution repeats faster
than the tiles can resolve, so instead of tiling it, fill the whole
circle flat with the width-weighted average color of one period --
the band-limit of the pattern. Compute the starting repeat directly
by division, bailing out on non-finite angles, and guard the inner
loop against clipped-segment spins that unsorted (contract-violating)
stop arrays could otherwise drive. The absolute-index 1000 cap is
gone: repeat gradients that legitimately need more repeats to cover
the full circle now render completely instead of being silently
truncated. The helper is also used by the hb-cairo glue, which
picks up the same bounds.
The ClusterFuzz reproducer drops from 27s / 7.8GB RSS locally to
under 0.01s / 8MB, each degenerate gradient collapsing to one flat
patch. All 96 sweep glyphs of test_glyphs-glyf_colr_1.ttf and 98
sweep glyphs of its variable version at three variation settings
render byte-identically in both SVG and PDF; full test suite passes.
https://oss-fuzz.com/testcase-detail/6490910482038784
Assisted-by: Claude Fable 5 <noreply@anthropic.com>
The edge-work estimator cast the result of the y-coordinate
subtraction to int64_t, after the subtraction had already happened in
int32_t. An edge spanning the clamped coordinate range could therefore
overflow before the work was capped to the surface height.
Widen both operands before subtracting, matching the existing edge
slope calculation, and add the minimized OSS-Fuzz reproducer to the
fuzz corpus.
Fixes: https://oss-fuzz.com/testcase-detail/5773854015029248
Assisted-by: OpenAI Codex <noreply@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 paint session budget charged consumed outline edges at a flat
weight of 16 each, but the rasterizer's real cost per edge is
proportional to the rows it crosses: each edge is walked once per
scanline it spans. A glyph made of near-full-height zigzag edges
costs edge-count times surface-height row-steps while being charged
only 16 per edge, leaving the multiplication with the paint-graph
traversal limits under-counted.
Replace hb_raster_draw_get_edge_count() with
hb_raster_draw_get_edge_work(), which sums one unit per edge plus
its span in rows, clamped per edge to the surface height (edges are
clipped to the surface during rendering). The paint charge sites
now charge this real scanline work with no artificial weight.
Suggested by Behdad. Both fuzzer reproducers stay at ~0.12s;
rendering of regular color fonts is byte-identical; full test suite
passes.
Assisted-by: Claude Fable 5 <noreply@anthropic.com>
Gather the five session work-budget limits introduced by the
preceding commits into a single commented block in hb-limits.hh,
explaining the shared design: per-subsystem limits multiply when one
subsystem drives another, so each driving session carries one
cumulative budget, initialized once per top-level entry and only
ever decremented. No functional change; HB_VARC_MAX_WORK gains an
int64_t cast for consistency with its siblings.
Assisted-by: Claude Fable 5 <noreply@anthropic.com>
The raster seed drives ~2048 COLR PaintComposite nodes each costing
a full-surface composite; the gpu seed drives a VARC composite glyph
whose components each load a large glyf leaf glyph. Both timed out
on ClusterFuzz before the preceding work-budget commits.
Assisted-by: Claude Fable 5 <noreply@anthropic.com>
The paint-extents backend extracts a full glyph outline via
hb_font_draw_glyph() for every clip-glyph paint node, so the COLR
paint-graph traversal limits multiply with the per-glyph outline
limits (glyf points, CFF interpreter ops) when computing color-glyph
extents.
Add a work_left counter to hb_paint_extents_context_t, reset by
clear() (both users -- COLR extents and hb_font_t's paint-based
extents fallback -- start sessions through it) to the new
HB_PAINT_EXTENTS_MAX_WORK limit. Replace the plain draw-extents
sink with a local counting variant so each clip-glyph draw charges
the outline points it consumed; once the budget is exhausted,
further extractions are skipped and degrade to an empty clip. This
mirrors the session budgets in the raster, GPU, and vector paint
backends.
Full test suite passes.
Assisted-by: Claude Fable 5 <noreply@anthropic.com>
The SVG and PDF paint backends extract a fresh glyph outline via
hb_font_draw_glyph() for every fill-glyph and clip-glyph paint node,
each with a fresh per-glyph budget (glyf points / CFF interpreter
ops), and append the formatted path data to the output document.
The COLR paint-graph traversal limits multiply with those per-glyph
limits, and the generated path data grows unboundedly.
Add a work_left counter to hb_vector_paint_t, reset per session by
hb_vector_paint_clear() to the new HB_VECTOR_MAX_PAINT_WORK limit
and charged with the bytes of path data generated by each outline
extraction. Once exhausted, further extractions are skipped: an
empty path (or empty clip path) keeps the document structure intact.
This mirrors the session budgets in the raster and GPU paint
backends.
Full test suite passes; normal SVG output is unaffected.
Assisted-by: Claude Fable 5 <noreply@anthropic.com>
The GPU paint encoder already bounds the number of clip-glyph
sub-blobs per paint walk (HB_GPU_PAINT_MAX_SUB_BLOBS), but each
encode re-extracts a full glyph outline with a fresh per-glyph
budget: 1024 sub-blobs times 200k glyf points still multiplies into
a fuzzer timeout, since the memoized sub-blob index is reset on
every clip push.
Add a work_left counter to hb_gpu_paint_t, reset per walk by
hb_gpu_paint_clear() to the new HB_GPU_PAINT_MAX_WORK limit and
charged with the curves consumed by each clip-glyph and clip-path
encode. Once exhausted, further clip encodes are skipped and the
walk is marked unsupported, matching the existing sub-blob-cap
degradation. This mirrors the session budgets added to the raster
paint backend and VARC.
Both fuzzer reproducers stay at ~0.12s locally. Full test suite
passes.
Assisted-by: Claude Fable 5 <noreply@anthropic.com>
VARC bounds its own composite-graph traversal (edge count, nesting
depth, decycler), and each leaf glyph loaded from glyf/CFF/CFF2 is
bounded by that table's per-glyph limit (HB_GLYF_MAX_POINTS,
HB_CFF_MAX_OPS), but the two budgets multiply: one composite glyph
can reference thousands of components, each drawing a leaf glyph
worth 200k points/ops, timing out the fuzzer.
Add a budget_left counter to hb_varc_context_t, initialized once per
top-level get_path/get_extents entry to the new HB_VARC_MAX_WORK
limit and shared by all leaf loads. Leaf loaders report their
consumption through a new optional int64_t *budget parameter: glyf
charges the points it processed (scratch.all_points holds exactly
this glyph's points), and the CFF/CFF2 charstring interpreter charges
executed ops, threaded through get_path/get_extents(_at) of both
tables. Once the budget is exhausted, remaining leaves are skipped
best-effort; a single in-flight leaf may overshoot by at most one
per-glyph limit. Existing callers (hb-ot-font) pass no budget and
are unchanged. CFF1 seac component recursion is left uncharged; it
is bounded at two extra charstrings per gated leaf.
Reduces the hb-gpu-fuzzer reproducer (VARC components each loading
large glyf leaf glyphs) from 3.75s to 0.13s locally (was >60s on
instrumented ClusterFuzz builds); rendering of the VARC hanzi and
hangul test fonts is byte-identical before and after. Full test
suite passes.
Assisted-by: Claude Fable 5 <noreply@anthropic.com>
The COLR paint-graph traversal is bounded by its own limits (edge
count, nesting depth), and each raster paint operation is bounded by
surface size, but the two budgets multiply: a font with ~2048 paint
nodes where each node costs a full-surface pass (PaintComposite's
pop_group compositing, push_clip_glyph's clip-buffer pass) performs
billions of pixel operations, timing out the fuzzer.
Add one cumulative work budget per paint session (everything painted
between two render/clear calls), tracked in hb_raster_paint_t and
initialized to the larger of a flat floor and a few full passes over
the surface, so client-sized large surfaces keep proportional
headroom. Pixel loops (composites, fills, gradients, images, clip
passes) charge their area; glyph-outline work charges the consumed
rasterizer edges with a fixed weight, read back through a new
internal hb_raster_draw_get_edge_count() helper. Once the budget is
exhausted, operations are skipped best-effort: clip pushes degrade to
empty clips and glyph-outline extraction is skipped entirely, so
per-glyph outline limits (glyf points, CFF interpreter ops) cannot
multiply with the caller's traversal limits either.
Reduces the fuzzer reproducer from 0.92s to 0.11s locally (was >60s
on instrumented i386 ClusterFuzz builds); rendering of regular color
fonts is byte-identical before and after. Full test suite passes.
Assisted-by: Claude Fable 5 <noreply@anthropic.com>
* [subset] Clamp variable advances to UFWORD range in plan
When instancing, the hmtx/vmtx advance is computed by adding the
HVAR/VVAR delta to the base advance. The delta is attacker-
controlled and unbounded, so the sum can go negative or exceed
65535. The negative case, cast to unsigned, produced advances
near 4 billion in hmtx_map; CFF::optimize_widths () then looped
over the full [min_w, max_w] width range, taking minutes (the
oversized cumsum resize fails cleanly, so this was a pure hang,
no memory unsafety).
Clamp the computed advance to [0, 0xFFFF], matching the UFWORD
range that hmtx/vmtx serialization stores and the hb_max (0.f, …)
clamp already used by the runtime metrics path.
Fixes a ClusterFuzz timeout in hb-subset-fuzzer (testcase
4846730722738176, minimized from timeout-fd8f4bd2a650). The
testcase went from >60s to 5ms; added as a fuzz seed. Full
meson test suite passes.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* [raster] Fix signed overflow computing row bottom at coordinate limit
edge_sweep_row () computed y_bot = y_top + ONE_PIXEL in int32. The
scanline loop clamps y_top itself to INT32_MAX, but when the surface
sits at the extreme of the 24.8 fixed-point coordinate space y_top
can be within ONE_PIXEL of INT32_MAX (0x7FFFFF00), and the addition
overflows: UBSan "2147483392 + 256 cannot be represented in type
'int'".
Saturate the addition at INT32_MAX using the same 64-bit-then-clamp
idiom already used for y_top and the x interpolation. Edges are
int32-clamped too, so no coverage exists beyond INT32_MAX and the
clipped bottom band loses nothing real.
Fixes ClusterFuzz issue 541858526 (testcase 5513551012495360).
Reproduced with a -Db_sanitize=undefined build: one UBSan report
before, clean after. Testcase added as a fuzz seed. Full meson
test suite passes.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* [raster] Cap font-derived surface dimensions at 4096 pixels per side
When no extents are set explicitly, the paint and draw contexts
derive the surface size from font data: glyph extents (which the
auto path in hb_raster_paint_glyph_impl () feeds through
set_glyph_extents ()) or the accumulated outline bounds in
hb_raster_draw_render (). A malicious font with a tiny upem and
huge glyph coordinates turns that into arbitrarily large
allocations: a 49 KB fuzz font produced several ~885 MB BGRA
surfaces live at once (root surface plus one per PaintComposite
push_group), nearly 4 GB total.
Add HB_RASTER_MAX_AUTO_DIMENSION (4096) to hb-limits.hh and clamp
width/height at the three font-derived sizing points: both
set_glyph_extents () implementations and draw render's
auto-size-from-edges path. Since push_group and clip surfaces
inherit fixed_extents, the cap bounds those too. Extents set
explicitly via hb_raster_{draw,paint}_set_extents () are not
limited.
Fixes an hb-raster-fuzzer out-of-memory finding (testcase
6344015149858816): peak RSS 3.47 GB before, 350 MB after.
Testcase added as a fuzz seed. Full meson test suite passes.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
When no extents are set explicitly, the paint and draw contexts
derive the surface size from font data: glyph extents (which the
auto path in hb_raster_paint_glyph_impl () feeds through
set_glyph_extents ()) or the accumulated outline bounds in
hb_raster_draw_render (). A malicious font with a tiny upem and
huge glyph coordinates turns that into arbitrarily large
allocations: a 49 KB fuzz font produced several ~885 MB BGRA
surfaces live at once (root surface plus one per PaintComposite
push_group), nearly 4 GB total.
Add HB_RASTER_MAX_AUTO_DIMENSION (4096) to hb-limits.hh and clamp
width/height at the three font-derived sizing points: both
set_glyph_extents () implementations and draw render's
auto-size-from-edges path. Since push_group and clip surfaces
inherit fixed_extents, the cap bounds those too. Extents set
explicitly via hb_raster_{draw,paint}_set_extents () are not
limited.
Fixes an hb-raster-fuzzer out-of-memory finding (testcase
6344015149858816): peak RSS 3.47 GB before, 350 MB after.
Testcase added as a fuzz seed. Full meson test suite passes.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
edge_sweep_row () computed y_bot = y_top + ONE_PIXEL in int32. The
scanline loop clamps y_top itself to INT32_MAX, but when the surface
sits at the extreme of the 24.8 fixed-point coordinate space y_top
can be within ONE_PIXEL of INT32_MAX (0x7FFFFF00), and the addition
overflows: UBSan "2147483392 + 256 cannot be represented in type
'int'".
Saturate the addition at INT32_MAX using the same 64-bit-then-clamp
idiom already used for y_top and the x interpolation. Edges are
int32-clamped too, so no coverage exists beyond INT32_MAX and the
clipped bottom band loses nothing real.
Fixes ClusterFuzz issue 541858526 (testcase 5513551012495360).
Reproduced with a -Db_sanitize=undefined build: one UBSan report
before, clean after. Testcase added as a fuzz seed. Full meson
test suite passes.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
When instancing, the hmtx/vmtx advance is computed by adding the
HVAR/VVAR delta to the base advance. The delta is attacker-
controlled and unbounded, so the sum can go negative or exceed
65535. The negative case, cast to unsigned, produced advances
near 4 billion in hmtx_map; CFF::optimize_widths () then looped
over the full [min_w, max_w] width range, taking minutes (the
oversized cumsum resize fails cleanly, so this was a pure hang,
no memory unsafety).
Clamp the computed advance to [0, 0xFFFF], matching the UFWORD
range that hmtx/vmtx serialization stores and the hb_max (0.f, …)
clamp already used by the runtime metrics path.
Fixes a ClusterFuzz timeout in hb-subset-fuzzer (testcase
4846730722738176, minimized from timeout-fd8f4bd2a650). The
testcase went from >60s to 5ms; added as a fuzz seed. Full
meson test suite passes.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
When the skipping iterator fails to find another kernable glyph,
resume at the position it reports instead of retrying from the next
glyph. This prevents a suffix of ignored marks from being scanned
repeatedly while preserving later feature ranges.
Assisted-by: OpenAI Codex <codex@openai.com>
Insertion state machines may emit glyphs during the end-of-text transition, when the buffer has no current input glyph. Emit the glyph first in that case and apply AAT metadata to the new output glyph instead of buffer->cur().
Add a regression font whose end-of-text action inserts the AAT deleted-glyph sentinel.
Assisted-by: OpenAI Codex <noreply@openai.com>
_hb_gpu_slug_single casts its horizontal ray leftward or rightward
depending on which side of the band's split point the fragment is on,
and likewise for the vertical ray. The crossing signs it accumulates
are the same either way.
But over a closed contour the signed crossings of a line sum to zero,
so counting the crossings on the left gives exactly the negative of
counting them on the right (clamp(0.5 + u) + clamp(0.5 - u) == 1, so
this holds for the antialiased partial coverages too). Whenever
hLeftRay and vLeftRay disagree, xcov and ycov therefore came out with
opposite signs, and _hb_gpu_calc_coverage's
abs (xcov * xwgt + ycov * ywgt) / (xwgt + ywgt)
subtracted the two estimates instead of averaging them.
Glyph interiors were unaffected -- the min (abs (xcov), abs (ycov))
term floors the result there -- so this never showed as a hole. It
showed as edges that antialias too light wherever both weights are
nonzero and the two estimates differ.
Flip the sign back after each loop. With a CPU port of
_hb_gpu_slug_single, comparing against plain Slug (rightward rays
over the full curve list, which is what the sign convention in
_hb_gpu_calc_coverage assumes), util/gpu/default-font.ttf at scale
163 rendered at 107px had 1700 pixels differing by more than 0.05
before this change, always too dark, and none differing by more than
0.001 after -- the split optimization is now exact.
Same fix in all four shading languages. The GLSL was checked with
glslc; the HLSL, MSL and WGSL edits are the same two statements and
were not machine-compiled.
Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.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>
None of the traversals require DFS order so BFS can be used instead which eliminates the possibility of stack overflow. For the queue we re-use the existing ordering_scratch_ space to avoid allocating any additional memory. As a bonus this fixes a bug in find_32bit_roots() that was the result of DFS traversal order.
All of the directed traversal methods are unified to a single common implementation.
The configs job only compiled harfbuzz.cc, now it compiles
harfbuzz-subset.cc too to catch config breakage in subset code.
Assisted-by: Claude Opus 5 <noreply@anthropic.com>
Follow-up to #6090 (GHSA-h2xh-wmpf-pwp5). #6090 saturated the
float->int conversions in emit_segment() via hb_clamp_to<int32_t>, but a
saturated edge endpoint (INT32_MAX) then overflows the ceil-round in the
auto-size path of hb_raster_draw_render():
int x1 = (xmax + HB_RASTER_PIXEL_MASK) >> HB_RASTER_PIXEL_BITS;
With xmax == INT32_MAX this is INT32_MAX + 255, signed overflow (UB).
UBSan fires on the accepted PoC (single spec-legal PaintTransform,
scale 32767.99) at the first painted glyph. Widen the +MASK step to
int64_t before the shift.
Also saturate the four float->int corner conversions in
hb_raster_paint_push_clip_rectangle() through hb_clamp_to<int32_t>, the
same unguarded pattern #6090 clamped elsewhere in this file (reachable
via PaintColrGlyph under a large PaintTransform); the subtraction is done
in double to avoid overflow, and NaN maps to INT32_MIN.
Verified with -fsanitize=address,undefined: the PoC (NEST=1 and NEST=9)
and full-font render of the base font produce zero runtime errors;
without the draw.cc change the PoC reports the signed-overflow above.
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.