* [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>
HarfBuzz
HarfBuzz started as a text shaping engine but has grown into a
full font platform — the ffmpeg of text shaping. It primarily
supports OpenType, but also Apple Advanced Typography.
HarfBuzz shapes the majority of text on modern screens.
HarfBuzz is optimized for robustness, correctness, and performance — in that order. Achieve all.
Try it live at harfbuzz-world.cc — an interactive playground for shaping, subsetting, rasterization, vector output, and GPU rendering, all running in your browser.
Here is a quick map of its components:
Core libraries
| Library | Description |
|---|---|
| libharfbuzz | Text shaping, draw API, paint API. Highly configurable (see CONFIG.md). Optional integration backends compiled in: hb-ft (FreeType), hb-coretext (macOS), hb-uniscribe (Windows), hb-directwrite (Windows), hb-gdi (Windows), hb-glib, hb-graphite2. |
| libharfbuzz-subset | Font subsetting and variable-font instancing. |
Auxiliary libraries
| Library | Description |
|---|---|
| libharfbuzz-icu | ICU Unicode integration. |
| libharfbuzz-cairo | Cairo rendering integration. |
| libharfbuzz-gobject | GObject/GI bindings. |
Rendering libraries
| Library | Description |
|---|---|
| libharfbuzz-raster | Glyph rasterization to bitmaps, including color fonts. Uses hb-draw and hb-paint. |
| libharfbuzz-vector | Glyph output to vector formats (currently SVG), including color fonts. Uses hb-draw and hb-paint. |
| libharfbuzz-gpu | Encodes glyph outlines for GPU rasterization (Slug algorithm). Provides shader sources in GLSL, WGSL, MSL, and HLSL. Live demo. |
Notable missing feature: font hinting (including autohinting) is not implemented. For hinted rasterization, use FreeType or Skrifa.
For simplified builds, amalgamated sources are available:
harfbuzz.cc (just libharfbuzz), harfbuzz-subset.cc (just
libharfbuzz-subset), or harfbuzz-world.cc (everything, driven
by a custom hb-features.h). For a live in-browser playground
plus a worked example of the world.cc single-file build, see
harfbuzz-world.cc.
Command-line tools
| Tool | Description |
|---|---|
| hb-shape | Shape text and display glyph output. |
| hb-view | Render shaped text to an image. |
| hb-subset | Subset and optimize fonts. |
| hb-info | Display font metadata. |
| hb-raster | Render glyphs to bitmap images. |
| hb-vector | Render glyphs to vector formats (SVG). |
| hb-gpu | Interactive GPU text rendering. |
The canonical source tree and bug trackers are available on github. Both development and user support discussion around HarfBuzz happen on github as well.
For license information, see COPYING.
API stability
The API that comes with hb.h will not change incompatibly. Other, peripheral,
headers are more likely to go through minor modifications, but again, we do our
best to never change API in an incompatible way. We will never break the ABI.
The API and ABI are stable even across major version number jumps. In fact, current HarfBuzz is API/ABI compatible all the way back to the 0.9.x series. If one day we need to break the API/ABI, that would be called a new library.
As such, we bump the major version number only when we add major new features, the minor version when there is new API, and the micro version when there are bug fixes.
Documentation
For user manual as well as API documentation, check: https://harfbuzz.github.io
Download
Tarball releases and Win32/Win64 binary bundles are available on the github releases page.
Development
For build information, see BUILD.md.
For custom configurations, see CONFIG.md.
For testing and profiling, see TESTING.md.
For using with Python, see README.python.md. There is also uharfbuzz.
For cross-compiling to Windows from Linux or macOS, see README.mingw.md.
To report bugs or submit patches please use github issues and pull-requests.
Developer documents
To get a better idea of where HarfBuzz stands in the text rendering stack you may want to read State of Text Rendering 2024. Here are a few presentation slides about HarfBuzz over the years:
- 2026 – HarfBuzz at 20!
- 2016 – Ten Years of HarfBuzz
- 2014 – Unicode, OpenType, and HarfBuzz: Closing the Circle
- 2012 – HarfBuzz, The Free and Open Text Shaping Engine
- 2009 – HarfBuzz: the Free and Open Shaping Engine
More presentations and papers are available on behdad's website. In particular, the following studies are relevant to HarfBuzz development:
- 2025 – AAT layout caches
- 2025 – OpenType Layout lookup caches
- 2025 – Introducing HarfRust
- 2025 – Subsetting
- 2025 – Caching
- 2025 –
hb-decycler - 2022 –
hb-iter - 2022 – A C library written in C++
- 2022 – The case of the slow
hb-ft>h_advancefunction - 2022 – PackTab: A static integer table packer
- 2020 – HarfBuzz OT+AAT "Unishaper"
- 2014 – Building the Indic Shaper
- 2012 – Memory Consumption
Name
HarfBuzz /hærfˈbɒːz/
From Persian حرف (Harf: letter) and باز (Buzz: open). Transliteration of the Persian calque for OpenType.
As a noun: The Open Source text shaping engine.
As an adjective: Insincerely talkative; glib. A nod to the GNOME project where HarfBuzz originates from.
The logo shows حرفباز in the IranNastaliq font, on a Damascus steel background.
Background: Originally there was this font format called TrueType. People and companies started calling their type engines all things ending in Type: FreeType, CoolType, ClearType, etc. And then came OpenType, which is the successor of TrueType. So, for my OpenType implementation, I decided to stick with the concept but use the Persian translation. Which is fitting given that Persian is written in the Arabic script, and OpenType is an extension of TrueType that adds support for complex script rendering, and HarfBuzz is an implementation of OpenType text shaping.
Users
HarfBuzz is used in Android, Chrome, ChromeOS, Firefox, Flutter, GNOME, GTK+, KDE, Qt, LibreOffice, OpenJDK, XeTeX, Adobe Photoshop, Illustrator, InDesign, Microsoft Edge, Amazon Kindle, PlayStation, Godot Engine, Unreal Engine, Figma, Canva, QuarkXPress, Scribus, smart TVs, car displays, and many other places.
