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>
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>
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
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>
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
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.
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
* [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.
* [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.
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
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>
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>
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
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
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
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
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
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
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
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
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
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
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>
* [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
* 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>
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.