Several internal helpers in the hb-vector library carry an
hb_svg_ prefix for historical reasons but are not SVG-specific —
they do generic math, transform points, compute extents, manage
blob recycling metadata, compare color stops, etc. Now that the
SVG-font input code is gone and these helpers are used equally
from the SVG and PDF output backends, rename them to match their
true scope.
Renames:
hb_sweep_gradient_tiles -> hb_vector_sweep_gradient_tiles
hb_svg_transform_point -> hb_vector_transform_point
hb_svg_set_glyph_extents_common-> hb_vector_set_glyph_extents_common
hb_svg_scale_precision -> hb_vector_scale_precision
hb_svg_decimal_point_* -> hb_vector_decimal_point_*
hb_svg_color_glyph_cache_key -> hb_vector_color_glyph_cache_key
hb_svg_color_glyph_cache_key_t -> hb_vector_color_glyph_cache_key_t
hb_svg_get_color_stops -> hb_vector_get_color_stops
hb_svg_color_stop_cmp -> hb_vector_color_stop_cmp
hb_svg_blob_meta_* -> hb_vector_blob_meta_*
All internal symbols — no public API affected.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove support for rendering glyphs whose source is the OpenType
SVG table, in both hb-raster and hb-vector. SVG is a large format
and our in-tree parser/renderer was half-finished; the complexity
was not justified by the partial coverage.
This is source-side only: hb-vector's SVG *output* backend (used
to serialize outline / COLR glyphs to SVG) is unaffected. Fonts
that have an SVG table will still load; glyphs served only by that
table will not render from these libraries.
hb-raster:
- Delete the hb-raster-svg-* file cluster (11 .cc/.hh files plus
hb-raster-svg.hh: parse, base, bbox, clip, color, defs,
defs-scan, fill, gradient, parse, render, use, context).
- Drop svg_glyph/svg_font/svg_palette state from
hb_raster_paint_t and the HB_PAINT_IMAGE_FORMAT_SVG branch in
the image callback.
- Drop hb_raster_paint_push_clip_path + hb_raster_svg_path_func_t
(only used from the SVG renderer).
- Drop zlib dependency (gzip decompression was only used for the
SVG table reader; libpng brings its own zlib linkage for PNGs).
hb-vector:
- Delete hb-vector-svg-subset.{cc,hh} (extracted font-SVG glyph
for embedding in SVG output).
- Remove the HB_TAG('s','v','g',' ') branch from the image paint
callback; PNG embedding remains.
- Drop svg_image tracking state from hb_vector_paint_t
(current_color_glyph_has_svg_image, current_svg_image_glyph,
current_face, svg_image_counter, subset_body_scratch).
- Simplify the color-glyph cache to store just def_id instead of
packed (def_id, image_like).
- Drop hb_svg_append_image_instance_translate.
Build wiring: src/meson.build, CMakeLists.txt, harfbuzz-world.cc
updated to match. Test suite: remove SVG-specific cases from
test/api/test-raster.cc and the handwriting-{svg,picosvg} vector
tests + expected fixtures.
~5700 LOC deleted, ~10 LOC added. Full test suite (240 tests)
passes.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Move the SVG case out of the hb_vector_paint_render switch into its
own static helper, matching the hb_vector_paint_render_pdf and
hb_vector_draw_render_{svg,pdf} pattern.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Default hb_vector_{draw,paint}_t::format to HB_VECTOR_FORMAT_INVALID
instead of HB_VECTOR_FORMAT_SVG.
- Update renamed hb_vector_{draw,paint}_set_{flat,precision} API docs
from "Since: 13.0.0" to "XSince: REPLACEME".
- Extract hb_vector_draw_render_svg() helper to match the
hb_vector_draw_render_pdf() pattern; move the misplaced
hb_vector_draw_render doc comment to the actual function and update
it to say "output blob" since the renderer is no longer SVG-only.
- Revert 14.0.0 NEWS entry edits; the API rename will be announced in
the next release entry.
- Update docs/harfbuzz-sections.txt to reflect the API renames.
- hb-vector tool: expose -O/--output-format with supported formats
"svg/pdf", validate format, update description string, and switch
PDF detection to g_ascii_strcasecmp for case-insensitive matching.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Fix: Algorithmic Complexity DoS in HarfBuzz Repacker
Introduce total iteration limits in overflow resolution loop and physical growth limits (vertices and spaces) to prevent Hang/OOM during subsetting of malicious fonts.
* Repacker: Move safety limits to hb-limits.hh as requested by Behdad
---------
Co-authored-by: default <default@zimbra.0day.lab>
When in fullscreen mode, pressing Escape now exits fullscreen
instead of closing the application. Pressing Escape again (or Q
at any time) still quits.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace all if/else chains on hb_vector_format_t with switch
statements, making the format dispatch explicit and extensible.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Rename files to follow hb-vector-{draw,paint}[-{svg,pdf}] convention:
hb-vector-svg-draw.cc -> hb-vector-draw.cc
hb-vector-svg-paint.cc -> hb-vector-paint.cc
hb-vector-pdf-paint.cc -> hb-vector-paint-pdf.cc
Rename internal API to match:
hb_vector_pdf_paint_funcs_get -> hb_vector_paint_pdf_funcs_get
hb_vector_pdf_paint_render -> hb_vector_paint_render_pdf
Remove stale declarations for hb_vector_svg_paint_funcs_get and
hb_vector_svg_paint_render which were declared but never defined.
Update meson.build, CMakeLists.txt, and harfbuzz-world.cc.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Drop "svg" from the names since flat/precision settings apply
equally to PDF output. The new names follow the hb_vector_draw_*
/ hb_vector_paint_* convention:
hb_vector_svg_set_flat -> hb_vector_draw_set_flat
hb_vector_svg_set_precision -> hb_vector_draw_set_precision
hb_vector_svg_paint_set_flat -> hb_vector_paint_set_flat
hb_vector_svg_paint_set_precision -> hb_vector_paint_set_precision
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
hb_extents_t::to_glyph_extents() rounded bounds to hb_position_t
before subtracting them. Extreme extents from fuzzed VARC and
raster paths could therefore overflow signed int arithmetic while
forming glyph widths or heights.
Compute the rounded endpoints in double, clamp the exported values
to hb_position_t, and reject non-finite results. Also avoid the
same overflow in the reverse hb_glyph_extents_t constructor, add
an internal regression for the shared helper, and include the
minimized raster testcase.
Fixes: https://oss-fuzz.com/testcase-detail/4826864710647808
Not-tested: Skipped by request.
Assisted-by: OpenAI Codex
hb_gpu_draw_get_extents() cast rounded bounds to hb_position_t
before subtracting them. A fuzzed glyph outline with an extreme
negative bound could therefore overflow signed int arithmetic while
forming width or height.
Compute the rounded bounds in double, reject non-finite values, and
clamp the exported extents to hb_position_t before returning them.
Add an API regression that covers the OSS-Fuzz testcase through the
public GPU draw API.
Fixes: https://oss-fuzz.com/testcase-detail/5918954634936320
Tested: meson test -C build --print-errorlogs
Assisted-by: OpenAI Codex
Move the sweep gradient color stop tiling (pad/repeat/reflect
across 0-2π) into a shared template hb_sweep_gradient_tiles()
in hb-vector-svg-utils.hh. Both SVG and PDF backends now call
it with their own patch emitter callback.
Also adds hb_color_lerp() to the shared header (fixing an R/B
channel swap bug in the PDF version's interpolation).
Net reduction of ~170 lines of duplicated tiling code.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add PNG image support to the PDF paint backend. Parses PNG chunks
to extract IHDR metadata and IDAT compressed data, then embeds
directly as PDF XObject Image with /FlateDecode and /Predictor 15
(PNG predictor), avoiding any re-encoding of pixel data.
Supports:
- Grayscale, RGB, Gray+Alpha, RGBA (8-bit)
- Indexed color (palette PNG) via /Indexed colorspace with PLTE
- Transparency for indexed PNG via SMask: decompresses IDAT,
un-filters PNG rows, maps palette indices to tRNS alpha values,
and emits a separate DeviceGray soft mask image
Tested with NotoColorEmoji.ttf (CBDT, indexed PNG with partial
alpha) and sbix.ttf (SBIX, RGBA PNG).
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Use the new push_group_for API to emit PDF ExtGState with /BM
(blend mode) when the compositing mode has a PDF 1.4 equivalent.
Maps 15 blend modes: Multiply, Screen, Overlay, Darken, Lighten,
ColorDodge, ColorBurn, HardLight, SoftLight, Difference, Exclusion,
Hue, Saturation, Color, Luminosity.
Porter-Duff modes (Clear, Src, Dst, etc.) have no direct PDF /BM
equivalent and fall back to the default (Normal/SrcOver).
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add a new push_group variant that receives the compositing mode
upfront. This lets backends like PDF emit blend-mode state before
painting the group content, avoiding the need to buffer and
retroactively wrap.
The default (nil) implementation calls hb_paint_push_group(), so
existing backends are unaffected.
Callers updated:
- COLR PaintComposite now calls push_group_for() for both groups
- Rust/fontations push_layer passes the mode through
- hb-raster SVG context accepts mode parameter (default SRC_OVER)
All 233 tests pass.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The previous implementation only covered start_angle to end_angle
with a fixed number of equal sectors, which broke repeat/reflect
extend modes and produced too few patches for oscillating gradients.
Rewrite to use the same tiling logic as the SVG sweep gradient:
map color stops to angles, handle pad/repeat/reflect extend modes,
and tile across the full 0-2π range. Each color stop interval
becomes one Coons patch (further split at 90° max for arc quality).
Tested with sweep_270_440_reflect_narrow glyph from
test_glyphs-glyf_colr_1_variable.ttf.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The buffer helper functions (append_str, append_len, append_c,
append_num, append_unsigned, append_hex_byte, append_base64,
recover_recycled, blob_from) are format-agnostic and used by
both SVG and PDF backends. Rename from hb_svg_* to hb_buf_*
to reflect this.
SVG-specific helpers (append_color, append_instance_transform,
transform_point, scale_precision, etc.) keep their hb_svg_*
names.
Assisted-by: Claude <noreply@anthropic.com>
Replace the pie-slice sector fallback with proper Type 6
Coons patch mesh shading. Each sector of the sweep is a
patch with:
- Outer arc approximated by cubic Bézier (kappa method)
- Inner arc at small radius to avoid degenerate geometry
- Radial straight edges connecting inner and outer
- Corner colors from the color line at sector boundaries
Sectors are limited to 90° for accurate Bézier arc
approximation, with a minimum of 4 patches per sweep.
The mesh data is encoded as a binary stream with 16-bit
coordinates, 8-bit color components, and 8-bit flags per
the PDF Type 6 specification.
Assisted-by: Claude <noreply@anthropic.com>
Decompose sweep gradients into 360 colored pie-slice sectors.
Each sector evaluates the color line at its midpoint and emits
a filled triangular path from the center to two points on a
large-radius arc.
Includes a color line evaluator that handles pad, repeat, and
reflect extend modes with linear interpolation between stops.
Assisted-by: Claude <noreply@anthropic.com>
Rewrite hb-vector-pdf-paint.cc with a proper PDF object
system that supports dynamic resource generation:
Alpha:
Solid colors with alpha < 1 now emit ExtGState objects
with /ca (fill opacity) and reference them via /GSn gs
in the content stream.
Gradients:
Linear gradients → PDF Type 2 (axial) shading with
Type 2/3 interpolation functions for color stops.
Radial gradients → PDF Type 3 (radial) shading.
Sweep gradients → solid fallback (no PDF equivalent).
Architecture:
A hb_pdf_resources_t collector tracks extra PDF objects
(ExtGState, Shading, Function) during painting. At render
time, these are emitted as numbered objects and referenced
from the Page's Resources dictionary.
Mark internal symbols HB_INTERNAL to fix check-symbols test.
Assisted-by: Claude <noreply@anthropic.com>
Remove the -xy/-yy negation from the PDF paint glyph
positioning transform. Font and PDF coordinates are both
Y-up, so no flip is needed. Same fix as was applied to
the draw path earlier.
Assisted-by: Claude <noreply@anthropic.com>
Add hb-vector-pdf-paint.cc with a complete set of PDF paint
callbacks for the HarfBuzz paint API:
push/pop_transform → q + cm / Q
push/pop_clip_glyph → q + path + W n / Q
push/pop_clip_rect → q + re + W n / Q
color → rg + re + f
push/pop_group → q / Q
gradients → solid fallback (first stop color)
The PDF paint backend reuses the draw funcs for glyph clip
path emission and shares the hb_vector_paint_t struct with
the SVG backend via hb-vector-paint.hh.
hb_vector_paint_glyph dispatches to SVG or PDF paint funcs
based on format. hb_vector_paint_render delegates to the
PDF render function for PDF output.
Tested with COLRv0 (RocherColorGX) — color layers render
correctly with proper clipping.
Assisted-by: Claude <noreply@anthropic.com>
Move the paint struct and color glyph cache key to
hb-vector-paint.hh so the upcoming PDF paint backend can
share the type. Convert the SVG-specific transform helper
methods to free functions.
No functional change.
Assisted-by: Claude <noreply@anthropic.com>
The pen coordinates from vector-output.hh are in font space
(Y-up), not SVG space. The Y-flip in compute_extents only
affects the extents, not the pen positions passed to
hb_vector_draw_glyph. Use pen_y directly.
Assisted-by: Claude <noreply@anthropic.com>
Font and PDF coordinates are both Y-up, so no Y-flip is
needed in the path data. The pen position from the SVG-space
layout is the only thing that needs negating.
Remove the Y negation from append_xy and the CTM from the
content stream. Set the glyph transform to identity with
negated pen_y.
Assisted-by: Claude <noreply@anthropic.com>
The previous CTM-based Y-flip reversed path winding, causing
inverted fills. Instead, negate Y directly in append_xy for
PDF format. This preserves winding direction and produces
correct non-zero fill results.
Assisted-by: Claude <noreply@anthropic.com>
Prepend a 1 0 0 -1 0 (ey+eh) cm to the content stream so
that the SVG-space (Y-down) path coordinates render correctly
in PDF (Y-up). Set the MediaBox to [ex 0 ex+ew eh].
Assisted-by: Claude <noreply@anthropic.com>
Add HB_VECTOR_FORMAT_PDF to hb_vector_format_t. The hb-vector
tool now produces self-contained PDF when invoked with -o out.pdf.
PDF path operators map directly from the draw callbacks:
move_to → m, line_to → l, cubic_to → c, close_path → h,
with quadratic-to-cubic promotion (PDF has no Q operator).
The render function builds a minimal PDF 1.4 with catalog,
page, and content stream objects plus a cross-reference table.
Implementation:
- Extract hb_vector_draw_t struct to hb-vector-draw.hh so
future backends can share it.
- Draw callbacks branch on format for SVG vs PDF syntax.
- hb_vector_draw_glyph and hb_vector_draw_render dispatch by
format.
- vector-output.hh selects format from file extension and
skips paint (color glyphs) for PDF.
Coordinate system needs refinement — the page layout inherits
the SVG Y-flip transform, placing glyphs at the top with
extra whitespace. Correct PDF coordinate handling is a
follow-up.
Assisted-by: Claude <noreply@anthropic.com>
Add draw and paint features to font.rs. Enable both by default in
Cargo.toml. This allow compilation without draw and paint functionality
enabled on the C++ side.
Assisted-by: Gemini CLI
Malformed reflected gradients can produce very large finite
gradient parameters. The raster backend normalized reflect
mode by casting floorf(t) to int, which can overflow and
drive LUT lookups past the fixed-size stack buffer.
Fold reflected coordinates with fmodf(), clamp LUT inputs
defensively, and add the minimized oss-fuzz raster
testcase to the corpus.
Fixes: https://oss-fuzz.com/testcase-detail/6597066439852032
Tested: meson test -C build
Co-Authored-By: OpenAI Codex <codex@openai.com>
hb_gpu_draw_encode() could allocate a fresh output buffer and then
return NULL before transferring ownership to a blob, leaking that
temporary buffer on late encode failures.
The recycled-blob growth path also tried hb_realloc() first and fell
back to hb_malloc() when that failed. Once the new buffer was committed
to the recycled blob, the old recycled buffer could be orphaned.
Free temporary buffers on the remaining late-failure exits and keep
the old recycled buffer alive until a replacement has been committed.
Tighten the GPU API recycle test to encode a larger second outline so
that reused-buffer growth stays covered.
Tested:
- meson test -C build
Assisted-by: OpenAI Codex <codex@openai.com>
edge_sweep_row() computed the clipped endpoint x coordinates with
int32_t subtractions before casting to int64_t. If an edge started at
INT32_MIN and the scanline clipped endpoint was near zero, ey - yL
overflowed before the slope multiply and UBSan flagged the raster
fuzzer path.
Keep the endpoint interpolation and follow-on dx math in 64-bit until
clamping back to int32_t. This preserves the existing rasterizer logic
while avoiding signed overflow for extreme edge coordinates.
Tested:
- meson test -C build
Assisted-by: OpenAI Codex <codex@openai.com>
libpng aborts via longjmp. Our PNG read/write helpers kept scratch
hb_vector_t objects as automatic locals after setjmp and then tried
to free them from the longjmp handler. Once longjmp fires, those
modified locals have indeterminate state, so the cleanup path can
miss live allocations and leak under the raster fuzzer.
Move the PNG scratch buffers and write accumulator into explicit
heap-backed state allocated before setjmp and cleaned up on every
exit path. This keeps both decode and encode cleanup deterministic
across libpng errors.
Tested:
- env LD_LIBRARY_PATH=/home/behdad/harfbuzz/build/src valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 ./build/test/fuzzing/hb-raster-fuzzer test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-subset-fuzzer-5684014636859392
- meson test -C build raster-fuzzer-chunk-0 raster-fuzzer-chunk-1 raster-fuzzer-chunk-2 raster-fuzzer-chunk-3 raster-fuzzer-chunk-4 raster-fuzzer-chunk-5 raster-fuzzer-chunk-6 raster-fuzzer-chunk-7 --wrap='valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1' --print-errorlogs
- meson test -C build
Assisted-by: OpenAI Codex <codex@openai.com>
Transformed clip rectangles kept their intersection math in unsigned
loop bounds after clamping only the lower edge to zero. When the
transformed upper edge stayed negative, the signed-to-unsigned cast
wrapped and raster clip reuse read past the previous alpha mask.
The same path also reused emitter-generated clip buffers without
clearing bytes outside the rows it rewrote, which let Valgrind see
uninitialized alpha values on later clip intersections.
Keep the clip intersection in signed ints until after the empty-range
check, and zero newly sized emitter clip buffers before partial writes.
Testing:
- env LD_LIBRARY_PATH=/home/behdad/harfbuzz/build/src valgrind --leak-check=full --error-exitcode=1 ./build/test/fuzzing/hb-raster-fuzzer test/fuzzing/fonts/clusterfuzz-testcase-minimized-hb-raster-fuzzer-4872362293264384
- meson test -C build raster-fuzzer-chunk-0 --wrap='valgrind --leak-check=full --error-exitcode=1' --print-errorlogs
- meson test -C build
Assisted-by: OpenAI Codex <codex@openai.com>
The raster paint clip code indexed non-rect clip alpha rows directly,
assuming the clip metadata always matched a full stride*height backing
buffer. Fuzzing showed that reused clip objects can reach those reads
with stale scalar state, which turns the row access in
push_clip_rectangle() into a heap-buffer-overflow.
Reset cached clip geometry on acquire, add a validity check for
non-rect alpha masks, and refuse to build new clip intersections from
an invalid mask. The fallback is an empty clip, which keeps the paint
path safe without affecting well-formed clips.
Testing:
- meson test -C build --suite fuzzing --print-errorlogs
- meson test -C build
Co-authored-by: OpenAI Codex <codex@openai.com>
The raster SVG renderer asserted that each element restored the paint
transform, clip, and surface stacks to their entry depths. Fuzzing
found malformed documents that violate that assumption and abort the
process in svg_render_element().
Replace the assertions with explicit stack restoration, discard any
extra group surfaces, and mark the render as failed if the renderer
cannot get back to the saved baseline. The top-level SVG entry point
now checks that failure bit and stops rendering cleanly instead of
crashing.
Testing:
- meson test -C build --suite fuzzing --print-errorlogs
- meson test -C build
Co-authored-by: OpenAI Codex <codex@openai.com>