Commit Graph
236 Commits
Author SHA1 Message Date
Behdad Esfahbod 22248564c1 [repacker] Move already-isolated overflow roots
Initialize every selected root's incoming-edge count before traversing
their combined subgraph.  This prevents later root initialization from
overwriting counts collected through an earlier root.

An overflow root still needs a new packing space when no duplication is
needed, so move already-isolated roots instead of treating that case as
an unsuccessful resolution attempt.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-02 02:36:20 -06:00
Behdad Esfahbod 5b104f8afe [repacker] Handle extended layout graphs
Discover GSUB/GPOS 1.2 lookups through LookupList2 and treat the
32-bit lookup-list link like other wide graph roots.  Also preserve
parent multiplicity when identical lookup subtables are promoted to a
shared extension wrapper.

Add coverage for 1.2 extension promotion and repeated subtable links.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-02 02:35:55 -06:00
Behdad Esfahbod d2e218ac26 [layout] Use 24-bit ClassDef format 3 values
ClassDef format 3 stores startGlyphID, glyphCount, and each class value
as uint24.  Use the medium integer type for the class array, select a
serializable format based on both glyph and class ranges, and keep the
subsetter size estimator in sync.

Test parsing and querying a class value above 65535, and test that the
serializer and size estimator select the matching format.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-10-01 13:29:55 -06:00
Behdad Esfahbod 17af97aae4 Merge remote-tracking branch 'origin/main' into beyond-64k
Reconcile the beyond-64K table type changes with the dependency API,
graph result handling, and variation-budget updates from main. Preserve
the branch's wider table variants while adopting the new behavior.

Build and test with Meson (281 passed, 1 skipped).

Assisted-by: OpenAI Codex <noreply@openai.com>
2026-10-01 12:59:54 -06:00
Kevin Hellemun 0d0b62575f fix(gcc 4.9.4): compilation errors
The current build for v14.5.0 fails to compile on gcc 4.9.4 which is
used on embedded Kobo systems. 

Ref: https://github.com/OGKevin/cadmus/pull/1005

Change-Id: 7a4bec5b5418bd0921b273d8d4a1e79b
Change-Id-Short: spvolnuouvyr
2026-09-21 11:02:29 -06:00
Garret Rieger 2a6c6b9b90 Add test for hb_result_t::from() that moves the input. 2026-09-04 17:08:08 -06:00
Garret Rieger 18d0fd1a6c Rework TRY macro to work the MSVC:
Split into one macro for void results, and a new TRY_ASSIGN() for when the Ok() value needs to be assigned.
2026-09-04 17:08:08 -06:00
Garret Rieger 2f291a46ae Convert repacker and graph code to utilize to hb_result_t.
Converts all error handling in the repacker/graph code to use hb_result_t.
2026-09-04 17:08:08 -06:00
Garret Rieger 8d08f87417 Fix possible memory leak in coverage-graph.hh 2026-08-27 21:11:10 +00:00
Garret Rieger 367657d74d Add some missing checks for alloc failure in repacker. 2026-08-27 21:11:10 +00:00
Garret Rieger 15fe46ee28 Use value instead of pointer in overflow record dedup.
Avoids issues with ownership of pointer memory.
2026-08-27 21:11:10 +00:00
Garret Rieger a897489430 Add HB_GRAPH_INVALID constant for marking error results in graph/repacker code. 2026-08-27 14:22:26 -06:00
Garret Rieger 7eac03d53c Add missing error handling for fallible operations in the repacker. 2026-08-27 14:22:26 -06:00
Garret Rieger 5f16f4ba68 In pair pos format 2 splitting only recompute coverage size when the included glyph set changes.
Assisted by Gemini
2026-08-26 14:24:53 -06:00
Garret Rieger c31bd6797a More documentation for traverse_directed_bfs(). 2026-07-31 18:05:07 -06:00
Garret Rieger 197d38a8a3 [subset] Convert repacker graph traversals to BFS.
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.
2026-07-31 18:05:07 -06:00
copilot-swe-agent[bot] 96f6aa848a Merge branch 'main' into beyond-64k
Resolve conflicts by taking hb_barrier() additions from main for all
switch dispatchers (COLR, Coverage, CursivePos, SinglePos,
ReverseChainSingleSubst) while keeping the beyond-64k extended
format cases.

For GDEF.hh: take main's clean GDEFVersion1_2<Types> template union
approach (which already handles beyond-64k via GDEFVersion1_2<MediumTypes>)
and incorporate the LigCaretList<Types> templating from beyond-64k,
expanding get_lig_carets() and collect_variation_indices() to dispatch
directly per version.

For coverage-graph.hh: keep beyond-64k's <Types> template but add
main's const qualifier to the vertex parameter.

For gsubgpos-graph.hh: keep beyond-64k's delegation to
OT::GSUBGPOS::get_lookup_list_field_offset() since GSUBGPOS uses the
flat struct approach in this branch.

For hb-ot-cmap-table.hh: keep beyond-64k's find_variation_selector_subtable()
which handles both format 14 and format 15 (beyond-64k).

Also fix PaintGlyph<Types>::paint_glyph out-of-line template definition
to include the template parameter, incorporating the get_solid_color
optimization from main.

Assisted-by: GitHub Copilot
2026-07-29 17:48:41 +00:00
Behdad Esfahbod da7f951ef0 Add more hb_barrier()s in switches (#6106)
Fixes https://github.com/harfbuzz/harfbuzz/security/advisories/GHSA-pmg2-m89x-pc6j
2026-07-27 19:20:18 -06:00
Qunxin Liu 2c875edbb6 [subset-repack] bug fixes (#6088)
* [subset-repack] fix potential out of bounds accesses

make sure we create a deep copy of the object before we mutate

* [subset-repack] fix is_shared(): only check real parents

* [subset-repack] add tests

* [subset-repack] apply AI proposed change

* address review comments

* [subset-repack] no need to duplicate shared liga_sets beforehand

Since we now would create a memory copy of the object before mutating
it, I think checking and duplicating shared liga_sets is not needed.
2026-07-21 11:49:06 -06:00
Qunxin Liu 8207419e0a [subset-repack] increase REPACKER_MAX_VERTICES limit to 800000 2026-07-21 11:16:26 -06:00
Behdad Esfahbod fc85680fec Revert "[subset-repack] bug fixes (#6077)"
This reverts commit 0b590d6b54.
2026-07-21 10:59:48 -06:00
Qunxin Liu 0b590d6b54 [subset-repack] bug fixes (#6077)
* [subset-repack] fix potential out of bounds accesses

make sure we create a deep copy of the object before we mutate

* [subset-repack] fix is_shared(): only check real parents

* [subset-repack] add tests

* [subset-repack] apply AI proposed change

* address review comments

* [subset-repack] no need to duplicate shared liga_sets beforehand

Since we now would create a memory copy of the object before mutating
it, I think checking and duplicating shared liga_sets is not needed.
2026-07-21 10:55:43 -06:00
Behdad Esfahbod 882ce8e6f3 [layout] Use 32-bit lookup offsets in LookupList2
Make the GSUB/GPOS v1.2 LookupList2 path use LookupList<MediumTypes>,
so the lookup count remains 16-bit while per-lookup offsets are widened
to 32 bits. Runtime lookup access now branches between the lower and
upper lookup-list layouts.

As of June 2026, the proposed GSUB/GPOS v1.2 spec points LookupList2 at
LookupList, which would leave per-lookup offsets at 16 bits. Note that
HarfBuzz intentionally widens those offsets because the proposed shape is
not suitable for beyond-64k fonts.

Keep the graph repacker on lower GSUB/GPOS tables for now, since it walks
the raw lookup-list object layout.

Testing: meson compile -C build util/hb-subset test-repacker
Testing: meson test -C build --suite shape --suite subset
Testing: build/util/hb-shape /tmp/fonttools-noto-sans-lookuplist2/NotoSans-merged.ttf 'test'
Testing: build/util/hb-shape /tmp/fonttools-noto-sans-lookuplist2/NotoSans-merged.ttf 'කොහොමද'
Testing: build/util/hb-shape /tmp/fonttools-noto-sans-lookuplist2/NotoSans-merged.ttf 'क्षि'

Assisted-by: OpenAI Codex
2026-06-07 20:59:44 +02:00
Behdad Esfahbod b1c5f20ef8 [layout] Keep extended ClassDef values 16-bit
ClassDef format 3 extends the glyph ID and glyph count fields,
but class values remain uint16.  Reading them through Types::HBUINT
made format 3 dense class arrays use a 24-bit stride, so class
lookups could return zero for valid glyphs.

Update the graph size estimator to use the same fixed value width
and compare concrete format sizes instead of using the old shortcut.

Tested with `meson test -C build`.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-06-06 13:55:38 +02:00
Behdad Esfahbod 2a543ecdd4 [layout] Align extended offsets with spec
Coverage format 3 and 4 widen their array counts, and coverage
range records also widen the coverage index value.  Account for the
larger records in the graph size estimator.

Use 32-bit top-level offsets where the extended GSUB/GPOS/context
formats specify long offsets, while leaving nested offset arrays as
24-bit offsets.  SequenceRuleSet2 is the exception where the rule-set
array offsets stay 16-bit and only the rule contents use extended
widths.

Tested with:
- meson compile -C build util/hb-shape
- git diff --check

Existing fontTools-generated Sinhala upper-case test fonts still lose
GSUB/GPOS script data and need follow-up debugging.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-06-06 13:19:16 +02:00
Behdad Esfahbod e6aeb529a4 [ot] Move shared types and dual helpers together
Move SmallTypes, MediumTypes, and the dual table accelerator
helpers into hb-ot-dual.hh. Keep Layout cache aliases in Layout
common and update standalone users to include the shared header.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-05 12:49:01 +02:00
Behdad Esfahbod 19de83dad2 [graph] Keep ClassDef size estimates incremental
Maintain the encoded ClassDef glyph set and range count as classes
are added instead of reconstructing them for every size estimate.

This avoids quadratic PairPos splitting on large class definitions.

Assisted-by: OpenAI Codex
2026-06-05 12:38:55 +02:00
Behdad Esfahbod 0bf6733c0e [graph] Reject non-v1 GSUB/GPOS graph roots
The repacker graph sanitizer accepted non-v1 GSUB/GPOS roots
because GSUBGPOS::get_size() returns only the version field size
for unsupported major versions. Graph specialization then still
consulted the numeric version and could read the v1.2 lookupList2
field from a too-small fuzz object.

Require version major 1 before using GSUB/GPOS graph-specific
lookup discovery.

Testing: meson test -C build test-repacker test-classdef-graph
Testing: meson test -C build --suite subset
Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-05 12:34:52 +02:00
Behdad Esfahbod 336d65cdab [graph] Guard beyond-64k classdef graph tests
The default build has HB_NO_BEYOND_64K enabled, so serializers reject
glyph IDs above 0xffff with an integer-overflow error. Keep the high
glyph ClassDef size checks for beyond-64k builds only.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-05 12:34:52 +02:00
Behdad Esfahbod 813558d2e9 [gpos] Template mark attachment arrays
MarkBasePos, MarkLigPos, and MarkMarkPos format 2 use nested
MarkArray2, BaseArray2, LigatureArray2, and Mark2Array2 tables
with 24-bit counts and offsets in different combinations.

Template the shared mark records and anchor matrices so format 1
continues to use SmallTypes while format 2 uses the widths specified
for the beyond-64k layout forms. Keep the subset graph wrappers bound
to their existing 16-bit forms.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-05 12:34:52 +02:00
Behdad Esfahbod ef538ebafa [graph] Clarify 24-bit layout splitter policy
Update graph splitter comments to document that 24-bit layout formats
are intentionally left unsplit because their relevant offsets are
already widened.

Testing: not run; comment-only change.

Assisted-by: OpenAI Codex
2026-06-05 12:34:51 +02:00
Behdad Esfahbod 8a7a5e9baa [graph] Account for 24-bit ClassDef size estimates
Update the ClassDef and Coverage size estimator used by graph
splitting to derive glyph and range widths from the included glyphs
instead of assuming 16-bit table formats. Keep ClassDef size selection
aligned with the serializer heuristic, including class breaks and the
fact that class zero is not encoded in ClassDef tables.

Add high-glyph test cases that compare the estimator against actual
24-bit ClassDef and Coverage serialization sizes.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-05 12:34:51 +02:00
Behdad Esfahbod fb91f3be90 [graph] Support 24-bit Coverage sanitization
Template the graph Coverage sanitizers on the layout type width and
dispatch formats 3 and 4 through the MediumTypes variants. This lets
graph sanitization accept 24-bit Coverage tables instead of rejecting
those formats outright.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-05 12:34:51 +02:00
Behdad Esfahbod 5f8d73cbe9 [graph] Support 24-bit ClassDef sanitization
Template the graph ClassDef format wrappers on the layout type width
and dispatch formats 3 and 4 through the MediumTypes variants. This
lets graph sanitization accept 24-bit ClassDef tables instead of
rejecting those formats outright.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-05 12:34:51 +02:00
Behdad Esfahbod a1a1002e59 [layout] Fold GSUB/GPOS version handling into header
Move the GSUB/GPOS versioned header fields back into GSUBGPOS
and select the active ScriptList, FeatureList, and LookupList
offsets from the table version.

Version 1.2 now uses the spec's 32-bit offset2 fields when they
are present, while the common list internals remain the existing
16-bit layout structures.

Testing: meson test -C build

Assisted-by: OpenAI Codex
2026-06-05 12:34:51 +02:00
Qunxin Liu 209a7237b9 [repacker] fuzzer fix: duplicate shared liga_sets before splitting (#5972)
fix for: https://oss-fuzz.com/testcase-detail/5291844211900416
2026-05-01 14:50:05 -06:00
Behdad Esfahbod 2adb01a47c [internal] Replace remaining vector resize(0) with clear()
Two callers were still using vector.resize(0) to drop accumulated
data: graph/serialize.hh's overflow tracking and hb_bit_set_t's
clear() (via its own internal resize()).  resize(0) on a vector
in error state short-circuits without zeroing length, leaving
stale entries that downstream code then walks as if valid.

Fix both:

 - serialize.hh: call overflows->clear() instead.
 - hb-bit-set.hh: reimplement clear() to zero length/population
   unconditionally by calling pages.clear() / page_map.clear()
   directly, bypassing the internal resize() that bails when
   `successful` is false.

Mirrors the March clear() fix in hb-vector.hh (commit d134f88824).

Assisted-by: Claude <noreply@anthropic.com>
2026-04-14 22:04:57 -06:00
jfkthame 603ab95602 Return size_t rather than unsigned int from get_size() (#5915)
* [subset] Return size_t rather than unsigned from get_size() methods

It's possible some get_size() computations during serialization
may overflow 32-bit arithmetic.

(The result of get_size() is used as size_t when allocating via
hb_serialize_context_t::extend(), but if the return value was
declared as unsigned int, the value may have wrapped resulting
in under-allocation.)

* [subset] Use size_t when accumulating subset_data_size

* [graph] Use size_t (rather than signed int64_t) for vertex_len variables

* Use size_t for sanitize_closure_t::stride to avoid narrowing
2026-04-13 11:01:19 -06:00
Qunxin Liu 380ae0122f [subset-repack] dont duplicate node that might be shared (#5889)
repacker will duplicate it if actually needed
2026-04-11 22:23:40 -06:00
Kyr1o5anddefault f099a260d9 Fix: Add safety limits to hb-repacker to prevent algorithmic complexity attacks (#5904)
* 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>
2026-04-10 18:06:24 -06:00
Qunxin Liu e601560b77 fix fuzzer issue: https://oss-fuzz.com/testcase-detail/6005602106277888
Do not use pointers that may point outside of the allocated memory region
2026-01-23 11:44:39 -07:00
Qunxin Liu b17fa8ef39 Fix fuzzer found heap-use-after-free crash (#5717)
Fixes https://oss-fuzz.com/testcase-detail/6005602106277888
2026-01-21 14:42:29 -07:00
Qunxin Liu babdb46be3 [repacker] bug fix for splitting shared subtables (#5686)
And fix splitting for ligatureSubst table with shared coverage table
2025-12-19 21:42:20 -07:00
Garret Rieger 09c14fa4f2 Fix fuzzer found memory leak. (#5643)
Fixes https://oss-fuzz.com/testcase-detail/6083012753424384
2025-11-14 02:27:35 -07:00
Behdad Esfahbod 346b8dcf93 Wrap formats in struct
Part of https://github.com/harfbuzz/harfbuzz/issues/5601

This was done automatically using codex, the ChatGPT coding
agent.
2025-11-11 12:29:06 -07:00
Behdad Esfahbod 2bcce37ffd [Coverage] Wrap format in a struct
Part of https://github.com/harfbuzz/harfbuzz/issues/5601
2025-11-11 02:24:50 -07:00
Qunxin Liu cb6e12bf3e [repacker] remap 24 bits links cause they could be roots (#5631) 2025-11-01 16:39:29 -06:00
Garret Rieger 07ee609f5a Fix invalid pointer conversions in graph Coverage. (#5622)
For #5604.
2025-10-20 20:06:43 -06:00
Qunxin Liu fdb80534e2 [subset-repacker] bug fix: copy markFilteringSet field if exists (#5579) 2025-09-23 15:32:41 -06:00
Garret Rieger 54ab8f0df4 [repacker] make repacker object ids stable.
Prior to this change the object id for a vertex in the repacker graph is it's position in the topological ordering. As a result after each sorting the object ids change. This decouples the topological sorting from the object id assignments. A separate ordering list is retained. This simplifies handling around object ids which no longer needs to account for them shifting, and improves performance by eliminating the step of reassigned link object ids after each sort.
2025-09-15 16:34:44 -06:00