Commit Graph
15 Commits
Author SHA1 Message Date
Koi 613f59727a [subset] Keep the format byte when serializing DeltaSetIndexMap format 1 (#6573)
* [subset] Keep the format byte when serializing DeltaSetIndexMap format 1

DeltaSetIndexMap::serialize() set u.format before calling the
format serializer, and DeltaSetIndexMapFormat01::serialize() then
calls extend_min(), which zero-fills the header. Format 0 survived
because its format value is 0, but a format 1 map (more than 65535
entries) came out with format 0, so readers took the upper half of
the 32-bit mapCount as a 16-bit count and lost the HVAR advance
deltas of the subset font.

Set the format inside DeltaSetIndexMapFormat01::serialize() after
extend_min(). Add a test-serialize case that checks both formats.

Fixes: https://github.com/harfbuzz/harfbuzz/issues/6440
Assisted-by: OpenCode

* [subset] Test DeltaSetIndexMap at the format boundary

Run the DeltaSetIndexMap serialize check with 65535, 65536 and 65537
entries so the <= 0xFFFF switch between format 0 and format 1 is
covered, and give the last entry a value no other entry has so a read
of the wrong entry is caught.

Assisted-by: OpenCode
2026-11-04 13:09:53 -06:00
Behdad EsfahbodandClaude Opus 4.8 9fec0b2ca5 [serialize] Keep push() pushing while only an overflow error is pending
pop_discard() and pop_pack() deliberately keep popping while the only
error is an INT/ARRAY/OFFSET overflow, but push() bailed on any error,
so any push/pop pair opened in that state popped the enclosing object.
GPOS mark-attachment subsetting reaches this when instancing overflows
an anchor coordinate and AnchorMatrix/LigatureArray/MarkArray report
success anyway: the serializer stack slips one level and
hb_subset_or_fail() aborts on the revert() assertion (or, without
assertions, dereferences a NULL current).  A crafted 344-byte variable
font instanced with e.g. --variations=wght=900 triggers it.

Give push() the same in_error () && !only_overflow () guard as the two
pops.  Objects pushed in that state stay empty (allocate_size() refuses
while in error), pop_pack() returns 0 for them and pop_discard()
releases them, so pairs stay balanced.  The object-pool-exhaustion
branch now records the error directly with err(), since
check_success(false) is a no-op once an error is already pending and
the matching pop would again pop the parent.

A unit test, test_push_pop_after_overflow(), is added to
test-serialize.cc; it fails on the unpatched header.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-GB4R872E.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-30 15:37:38 -06:00
Mar 4a60bf8333 [layout] Sanitize substitute feature params with their feature tag
FeatureTableSubstitutionRecord sanitized its substitute Feature with
no feature tag, so FeatureParams::sanitize() checked nothing for it.
The subsetter reads those params by the tag of the feature they
replace: Record::subset() when instancing applies the substitutes,
and FeatureTableSubstitutionRecord::subset(),
FeatureVariations::collect_name_ids() and
_features_have_equal_params() since #6349 and #6350.  A size, ssXX
or cvXX substitute could thus be read past the end of the table.

Pass the FeatureList down from GSUBGPOS::sanitize() and sanitize
each substitute with the tag of its featureIndex, the tag every
reader uses.

Test: test_feature_substitution_params_sanitize in test-serialize.

Assisted-by: Claude
2026-10-19 12:04:29 -06:00
Behdad Esfahbod 1b352dfc0f [ot] Keep lookup-variation shape-plan keys compact (#6396)
* [ot] Keep lookup-variation shape-plan keys compact

Resolving every feature's lookup set into the shape-plan key copies
shared lookup lists once per feature, even when shaping never uses those
features. Small fonts can therefore retain large keys and allocate
another copy on every cache lookup.

Store sorted offsets of distinct satisfied conditions instead. Evaluate
shared tables and conditions once, and expand lookup sets only when
building selected features. Preserve default lookups and feature-table
substitutions, and adapt full-axis instancing to resolve retained
features from the same compact condition state.

Condition outcomes form a conservative cache key: different outcomes
may keep otherwise equivalent lookup unions in separate plans.

Add regressions for shared records, null and shared conditions,
overlapping lookup sets, empty overrides, default lookups, sorting,
and allocation failure. The full Meson suite passes (292 passed,
1 skipped). ASan/UBSan runs pass on 64 failing-malloc inputs, and the
touched code compiles with HB_NO_VAR under C++11.

Assisted-by: OpenAI Codex <codex@openai.com>

* [test] Use an unsigned lookup condition count

Adding two boolean expressions produces an int, which GCC rejects when
compared with the unsigned vector length under -Werror=sign-compare.
This prevents the new regression test from compiling in the Linux,
docs, Rust, and Valgrind jobs.

Store the expected count as unsigned before comparing it with the
vector length. Reproduced the error with GCC C++11; the corrected test
builds and runs with GCC. The full Meson suite passes (292 passed,
1 skipped).

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-14 20:33:52 -06:00
Behdad Esfahbod ccb44730a8 [subset] Propagate failed class mappings before serialization
The PairPos allocation sweep exposed a pre-existing serializer assertion.
A failed class-map allocation supplies invalid class indices, which are
then reported as integer overflow. Continuing with that recoverable error
can unbalance nested serializer objects before a snapshot rollback.

Propagate class-map allocation errors before remapping or serializing
indices. Also propagate failure to collect PairPos format-2 columns so
an empty vector cannot silently omit the positioning matrix.

Add a failed-map regression. Tested with the full Meson suite (279
passed), C++11 reduced-feature checks, and Address/UndefinedBehavior/
LeakSanitizer allocation sweeps over the new fixtures (2334 attempts).

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-05 18:11:23 -06:00
Behdad Esfahbod cf0409d040 [subset] Preserve instanced device-only positioning values
A ValueRecord can contain a variation device without the corresponding
base placement or advance field. Instancing updated only existing base
fields, so the default delta was lost when the device was removed.

Add the corresponding base field when its default delta is nonzero and
initialize absent source fields to zero before applying that delta.
Test all four device fields for partial and complete instancing.

Tested: meson test -C build (261 passed, 1 skipped), and a C++11
experimental-api subset amalgamation syntax check.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-02 13:59:06 -06:00
Behdad Esfahbod def9e67160 [test] Fix null-condition fixture object sizes
Use the real nil Condition for format 0 and provide full-size, aligned
storage for the nested-condition binary fixtures.  This avoids UBSan
object-size violations in test-serialize.

Tested with the combined ASan/UBSan test-serialize target and the full
Meson test suite.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-02 03:21:22 -06:00
Behdad Esfahbod c2b308a271 [ot] Treat null conditions as true
Condition offsets of zero denote a true condition.  Represent that through
the nil Condition's reserved format 0 in evaluation, dependency collection,
and subsetting, preserving nested null offsets where possible and
materializing top-level nulls as constant-true format 2 conditions.

Add coverage for direct and nested null-condition evaluation, variation
index collection, and serialization.

Tested with the full Meson test suite.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-02 03:05:32 -06:00
Behdad Esfahbod c0bd381bd7 [subset] Serialize 24-bit chained-rule glyphs
Use the chained rule type width for backtrack, input, and lookahead arrays. The hardcoded 16-bit writes truncated extended glyph IDs and shifted the lookup-record array.

Add a byte-level regression covering all three glyph arrays.

Tested with: meson test -C build --print-errorlogs

Assisted-by: OpenAI Codex
2026-10-01 14:15:54 -06:00
Behdad Esfahbod 31d082d84a [subset] Serialize 24-bit sequence-rule glyphs
Use the rule type width when remapping glyph-keyed sequence rules. Writing HBUINT16 truncated extended glyph IDs and misaligned the following lookup records.

Add a byte-level serializer regression for a remapped glyph above 65535.

Tested with: meson test -C build --print-errorlogs

Assisted-by: OpenAI Codex
2026-10-01 14:14:32 -06:00
Behdad Esfahbod 75f919876f [src/test-*] Use hb_always_assert() which isn't compiled out under NDEBUG
Part of https://github.com/harfbuzz/harfbuzz/issues/5418
2025-07-25 03:00:38 -06:00
Garret Rieger c1e280ea78 [reorg] Move Coverage, RangeRecord into new namespace layout. 2022-07-13 20:25:13 -06:00
Behdad Esfahbod bad5c94562 [test] Remove HB_UNUSED 2022-01-23 10:53:19 -07:00
Behdad Esfahbod 6c09a8b5b0 [test-serialize] Assert len 2022-01-23 10:52:13 -07:00
Behdad Esfahbod 76c6f4164f [test] Add test-serialize 2022-01-23 10:43:37 -07:00