Commit Graph
1121 Commits
Author SHA1 Message Date
Behdad EsfahbodandClaude Opus 4.8 8f09a11184 [face-builder] Limit builder faces to 65535 tables
A builder face must always be serializable into an sfnt, but
hb_face_builder_add_table() accepted any number of tables while the
table directory's numTables is 16-bit.  Serializing a 65536th table hit
the assert in BinSearchHeader::operator= (or, with NDEBUG, truncated the
count and then looped forever through hb_face_reference_blob()'s retry).
The subsetter reaches this with HB_SUBSET_FLAGS_PASSTHROUGH_UNRECOGNIZED
because glyf::subset() always adds a 'loca' the source need not have.

Enforce the limit where tables are added, so the subsetter fails cleanly
at plan->add_table() and a builder face can always be written out;
replacing an existing tag is still allowed.  Also stop
hb_face_reference_blob() from recursing into itself on the fallback
builder it just built (serialize it directly with reference_table()):
otherwise a builder that cannot produce a blob is retried without end.

A regression test in test/api/test-get-table-tags.c adds 65535 tags,
checks the 65536th is refused, that replacement still works, and that
the serialized blob has the expected size.

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

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-30 15:27:31 -06:00
Behdad EsfahbodandClaude Opus 4.8 db0231fc12 [subset] Free the replaced override string in override_name_table()
name_table_overrides stores hb_malloc()ed strings as plain hb_bytes_t
values, so the invariant that every stored string is freed exactly once
in ~hb_subset_input_t broke when set() silently overwrote an existing
key: overriding the same name record more than once on one input leaked
the previous copy, and so did a NULL (remove) after a non-empty
override.

hb_subset_input_override_name_table() is the only place that allocates
these strings, so fix it there: look the record up with has(&old) and
fini() it in place before set() (fini nulls the pair, so no path frees
twice, and the lookup happens before set() can reallocate the table).
Also free the fresh copy and return false when set() cannot store it,
instead of leaking it and returning true.  hb_subset_plan_t copies the
map and frees its own copies, so it is unaffected.  No public API/ABI
change.

A regression line in test_subset_name_overrides overrides one record
twice; only the last string survives and the first must not leak.

Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-8SA3SRW4.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-30 15:26:52 -06:00
Behdad EsfahbodandClaude Opus 4.8 9c093444ef [subset] Honour len in hb_subset_axis_range_from_string()
The function documents len as the length of str, but located the ':'
separators with strpbrk() and matched "drop" with strcmp(), both of
which scan to the next NUL byte.  A caller passing an exact-length,
non-NUL-terminated slice therefore got an out-of-bounds read, and bytes
beyond len could change or reject the parsed range.

Bound every scan by str+len: each strpbrk() becomes memchr() bounded by
end, the strcmp() becomes a len==4 && hb_memcmp() check, and the empty
-piece test !*str becomes str == end.  This is the same discipline the
sibling parsers hb_feature_from_string()/hb_variation_from_string()
already follow.  For len == -1 (the only in-tree caller) len becomes
strlen() first, so behaviour is unchanged.  No public API/ABI change.

A regression test in test/api/test-subset.c passes prefixes of longer
literals with an explicit len and checks the NUL-terminated cases still
parse as before.

Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-IL9ZX304.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-30 15:26:47 -06:00
Behdad Esfahbod 6156c7b4a7 [subset] Validate custom glyph mappings before assigning output ids (#6479)
Glyph zero is always reserved for .notdef. Reject mappings that assign
another retained glyph to it, so the output list has one entry per id.

Also bound the resulting glyph count by the widest supported count
field, MAXP's HBUINT24. Account for the unmapped glyphs and the initial
slot before assigning ids, avoiding wraparound and oversized counts in
table subsetters. The limit applies to the count, not the highest id.

Document these constraints and test valid renumbering, gaps, ignored
remapping of .notdef, reserved-id collisions, and out-of-range counts.
The regression and stock hb-subset both reproduce the issue under ASan
before the fix. All 293 tests pass after it, including the subset suite;
the API subset tests and command-line checks also pass ASan and UBSan.

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

Assisted-by: OpenAI Codex
2026-10-29 21:01:05 -06:00
Behdad Esfahbod 4aebec5702 [subset/cff1] Bound preprocessing map lookups for output gaps (#6481)
A custom glyph mapping can leave unassigned output glyph IDs beyond
the source glyph count. The preprocessing glyph-to-SID map only covers
source glyphs, so use the existing charset lookup for those gaps and
skip the map-based range shortcut there.

Compare plain and preprocessed subsets of existing name-keyed and
CID-keyed fonts with output gaps. The new regression fails under ASan
before the fix. The complete ASan/UBSan Meson suite passes afterward
(293 tests, including 23 CFF1 API subtests).

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

Assisted-by: OpenAI Codex
2026-10-29 20:57:13 -06:00
Behdad Esfahbod 21a2f7c43e [repacker] Reject output sizes that cannot fit a blob (#6478)
The graph total is size_t, while the output vector allocation takes an
unsigned int. Check the total against the blob length limit before that
conversion, so the allocation and serialization context use the same
size. Totals above INT_MAX cannot produce a valid output blob anyway.

Add a public-API regression whose objects share their backing storage,
keeping its memory use small while exercising a large graph total.

Testing: meson test -C build (292 passed; check-symbols skipped on
macOS), plus test-subset-repacker with ASan and UBSan. The regression
reproduces the invalid write without the check and fails cleanly with it.

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

Assisted-by: OpenAI Codex
2026-10-29 20:56:03 -06:00
Behdad Esfahbod f030bd2186 [ot-layout] Convert script tags for hanging baseline synthesis (#6467)
The baseline fallback accepts an OpenType script tag but compared it
with hb_script_t values. Convert the tag before choosing the glyph
used to synthesize the hanging baseline.

Exercise Bengali's old and new OpenType tags, Tibetan, and the script
and language entry point. The updated test fails before the fix
(622 versus 600); the full Meson suite passes (293 tests).

Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-COIT72UF.

Assisted-by: OpenAI Codex
2026-10-29 19:28:41 -06:00
Behdad Esfahbod df19e5053b [raster] Keep the interior of transformed rectangle clips (#6470)
The point-in-quad test rejected the interior side of each edge for
both winding orders. Reverse the comparisons for rectangle and mask
intersections, and clarify how the edge normal depends on winding.

Add a regression for skew, reflected skew, and rotation, with one or
two nested rectangle clips to exercise both intersection paths. The
center pixel was transparent before the fix. The full Meson suite
passes (293 tests).

Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-AM92X98M.

Assisted-by: OpenAI Codex
2026-10-29 19:07:51 -06:00
Behdad Esfahbod 879be16fdf [ot-metrics] Use the vertical descender in the fallback (#6466)
Fonts without vhea returned the ascender for the vertical descender
metric. Read the descender from the synthesized vertical font extents,
as the horizontal fallback already does.

Add a regression comparing all three fallback vertical metrics with
the font extents. It fails before this change (1024 versus -1024).
The full Meson suite passes (293 tests).

Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-4UNO2SK8.

Assisted-by: OpenAI Codex
2026-10-29 18:52:24 -06:00
Behdad Esfahbod 1e6a7f38ee [cff] Reject INDEX item counts that do not fit (#6465)
CFF1 INDEX counts are 16-bit. Serializing a larger iterator truncated
its count before reserving the offset array, then wrote offsets for
every item. Check the count before allocating or writing the offsets.

Test the CFF1 boundary and the corresponding valid CFF2 counts, and
reject a subset glyph mapping that overflows the CharStrings INDEX.
Both regressions fail before this change. The full Meson suite passes
(293 tests), including the subset and API suites.

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

Assisted-by: OpenAI Codex
2026-10-29 18:31:46 -06:00
Behdad Esfahbodandnussaiba shaikh 404378164a [raster] Keep paint surfaces and budgets tied to the active root (#6464)
Changing extents during painting could allocate small group surfaces
against the original root and clip, causing out-of-bounds reads and
writes. Keep all session surfaces at the root's extents.

Use the same extents for group clear charges and pixel budget
recharges, so changing the configured rectangle cannot undercount
work on the active image. Document that render clears extents rather
than deferring a mid-session change to the next image.

Adapt the pixel regression from #6450 and check the render lifecycle.
Add an internal test for new and cached group clear charges and
budget recharging, using small buffers.

Reproduced the heap overflow on main under ASan. The budget test
fails with #6450. With this change, both raster test targets pass
under ASan+UBSan and the full Meson suite passes (274 tests).


Assisted-by: OpenAI Codex

Co-authored-by: nussaiba shaikh <nussaibah@bugqore.com>
2026-10-29 17:04:03 -06:00
Behdad Esfahbodandnussaiba shaikh d19879d033 [font] Clamp scaled glyph extents using stored bearings
Saturated int32 extents can round up to 2^31 when converted to float.
Clamp each scaled field before converting back to hb_position_t.
Compute width and height in double relative to the stored, clamped
bearings, preserving the existing formulas when a bearing saturates.

Adapt the COLR clip-box regression from #6459 and cover positive and
negative scales. At default scale, rounding INT32_MAX up to 2^31
leaves a one-unit extent relative to the clamped bearing.

Reproduced the original float-cast-overflow under UBSan. After the
fix, the color, extents, and font-scale API tests pass under UBSan,
and the full Meson test suite passes (273 tests).

Co-authored-by: nussaiba shaikh <nussaibah@bugqore.com>
Assisted-by: OpenAI Codex
2026-10-29 15:42:53 -07:00
Behdad Esfahbod a6214eefde [subset] Propagate CFF1 encoding range overflow errors
Returning false without setting a serializer error treats the CFF
subset as empty and silently drops its outlines. Record an error when
format 1 needs more than 255 encoding ranges so subsetting fails.

Reuse the many-codes fixture to check that 255 ranges still succeed
and 256 ranges fail. The regression fails before the fix.

Testing: meson test -C build (273 passed).

Assisted-by: OpenAI Codex
2026-10-29 15:35:51 -07:00
Beleniuc Ilie 4868fd314f [subset] Use CFF1 Encoding format 1 for more than 255 codes (#6460)
A format 1 Encoding can give codes to more than 255 glyphs, since
codes may repeat across ranges. When the subset keeps more than 255
of those glyphs, as with retain-gids, plan_subset_encoding() hit
assert (subset_enc_num_codes <= 0xFF).

Choose format 0 only when it can hold the codes, and fail cleanly in
the format 1 serializer instead of truncating nRanges past 255.

Add a test font whose format 1 Encoding covers 768 glyphs, and the
reporter's font to the fuzzing corpus.

Fixes: https://github.com/harfbuzz/harfbuzz/issues/6031
Assisted-by: Claude
Assisted-by: OpenAI Codex
2026-10-29 16:35:22 -06:00
Behdad Esfahbod c305720f01 [subset] Handle seac operands returned by a subroutine (#6463)
A subroutine can push all four seac operands, return, and leave the
glyph's own endchar to consume them. Treat callsubr and callgsubr
immediately before endchar as possible seac suffixes even when no
subroutine contains endchar.

Add a synthetic CFF1 regression font for the operand-only subroutine
case.

Assisted-by: OpenAI Codex
2026-10-29 16:25:35 -06:00
Behdad Esfahbod 2c0df50ce1 [subset] Make CFF1 seac precheck conservative (#6458)
A subroutine can terminate a glyph with endchar, and dotsection preserves
live operands. Account for both cases when deciding whether a CFF1
charstring can form a seac composite.

Cache whether any subroutine may contain endchar so ordinary fonts keep
the fast trailing-byte check. Skip component closure when all glyphs are
already retained, except when computing reusable accelerator metadata.

Add regressions for endchar in a local subroutine and operands preserved
across dotsection.

Assisted-by: OpenAI Codex
2026-10-27 18:05:47 -06:00
Behdad Esfahbod f306676520 [subset] Tighten CFF2 absolute rounding (#6443)
Clear flex-depth deltas when they all round to zero and reject unexpected
operators in the absolute-rounding pass. Cover static fractional operands
in a charstring that also contains blends.

Remove command-capture branches made redundant by the full-instancing
control flow.

Testing: meson test -C build (295 passed, one skipped).

Assisted-by: OpenAI Codex
2026-10-27 15:42:35 -06:00
Behdad Esfahbod 55995d5763 [depend] Guard format 6 test in reduced builds
Context format 6 is unavailable when HB_NO_BEYOND_64K is defined, so
do not register its dependency test in that configuration.

Tested with the default test-ot-depend target, an
HB_NO_BEYOND_64K test-ot-depend build, and the full Meson test suite.

Assisted-by: OpenAI Codex
2026-10-27 13:44:40 -07:00
nussaiba shaikh d2202126e2 Read 24-bit coverage offsets in ContextFormat3_6::depend
ContextFormat3_6<MediumTypes> (context format 6) stores its input
Coverage offsets as Offset24, but depend() passed them to
context_depend_lookup() cast to HBUINT16, so every input position
after the first decoded the wrong bytes as its offset.
intersects_coverage() then followed that value to a Coverage table
sanitize never checked.

With small offsets the misread value is 0, which points at the
subtable header, and the nested lookup's dependencies are silently
dropped.  A crafted rule can instead point the misread offset at bytes
shaped like a large Coverage, and CoverageFormat1_3::intersects() reads
past the end of the GSUB blob (ASan heap-buffer-overflow via
hb_subset_depend_from_face_or_fail).

The other ContextFormat3_6 methods pass coverageZ.arrayZ + 1 as is and
let glyph_data_t pick the width.  Do the same here.
ChainContextFormat3 has the same cast but only has a 16-bit
instantiation.

Add a format 6 font and test to test-ot-depend.c; it fails without
the fix.  Tested with meson test under ASan+UBSan with
-Dexperimental_api=true.

Assisted-by: Claude
2026-10-28 00:03:22 +05:30
Behdad Esfahbod 75d8ac5d23 [subset] Reject unsupported symbolic CFF2 delta products (#6434)
Without coordinates, blend_arg_t stores only a flat delta vector.
A blend used as a later blend's delta loses its own deltas, changing
outlines during partial instancing or desubroutinization.

Reject that case in the usage and flatten passes. Retained subroutine
collection needs only blend identity, and full instancing evaluates
blends numerically, so keep both paths working. Mark CFF2 planning
failures as serialization errors so the subset API returns failure
instead of a face missing its outline table.

Add a generated two-axis font and exercise retained subsetting, full
instancing, rejected partial/desubroutinized products, and supported
nested defaults. The regression fails before the fix. Full Meson suite:
272 passed, one skipped.

Assisted-by: OpenAI Codex
2026-10-22 13:04:52 -06:00
Behdad Esfahbod 51c6d7676c [subset] Recompute glyph headers when instancing at default (#6436)
A partial TrueType instance can round a child's points and its
component offset independently. A later full instance at the remaining
axes' defaults recalculates bounds but leaves the source glyph header
unchanged, so it can disagree with the stored component geometry and
with the updated global bounds.

Compile glyphs through the owned-byte path for default pins as well,
and free those buffers on both serialization and failure paths.

Add a generated regression where partial instancing stores child xMax
11 and component offset 1, then default instancing must write xMax 12.
The assertion fails before the fix. The full Meson suite passes with
272 tests successful and one skipped; OTS accepts the source fixture.

Assisted-by: OpenAI Codex <codex@openai.com>
2026-10-22 12:55:36 -06:00
Khaled Hosny 66130edd88 [beyond-64k] Enable by default 2026-10-22 19:31:32 +03:00
Behdad Esfahbod dde7da182e [subset] Reject CFF calls without an immediate subroutine number
Retained subroutine remapping assumes the number preceding a call is
in the same program. Caller-supplied targets violate that assumption
and can silently change glyph outlines when unused subroutines are
removed. Enforce the existing support boundary in CFF1 and CFF2.

Report plan failures as serialization errors, rather than silently
dropping the CFF table. Explicit desubroutinization still handles the
regression fonts and preserves both outlines.

Validation: full Meson suite, 272 passed and one skipped.

Assisted-by: OpenAI Codex
2026-10-22 17:06:10 +03:00
Behdad Esfahbod 4fc369ca36 [subset] Preserve long CFF DICT byte spans
Private DICT entries can accumulate several CFF2 blends before their
final operator. An eight-bit byte count truncated these spans modulo
256 during serialization, producing malformed output.

Use a full-width count and cover a 579-byte Private DICT with forty
variation regions and fourteen blended BlueValues.

Validation: full Meson suite, 272 passed and one skipped.

Assisted-by: OpenAI Codex
2026-10-22 17:06:10 +03:00
Behdad Esfahbod de3011962e [subset] Round CFF2 instances on absolute coordinates (#6427)
Rounding relative charstring operands independently accumulates errors,
opening contours and displacing stem hints after instancing. Track
absolute outline coordinates and stem edges, round their defaults and
surviving variation deltas, then emit relative operands again.

Preserve compact path operators. Conservatively retain relative rounding
for every glyph containing flex1, avoiding variation-dependent direction
analysis. Leave charstrings without blends unchanged.

Add a generated regression font covering closed contours, compact curves,
flexes, masks, and fractional static operands. Check full and partial
instances, contour closure, point accuracy, and the flex1 fallback. Refresh
the existing serialized CFF expectations.

Testing: the complete Meson suite passes (294 passed, one skipped), as do
the CFF2 API tests under ASan and UBSan.

See-also: https://github.com/fonttools/fonttools/pull/4338
Assisted-by: OpenAI Codex
2026-10-22 07:01:35 -06:00
Behdad Esfahbod 7da9b5df11 [subset] Zero bounds when a TrueType instance has no outlines (#6435)
When every retained glyph is empty, the glyf instancer leaves the
head bounds accumulator at its inverted initial sentinels. Reset the
accumulator after processing all glyphs so head has zero bounds.

Extend the zero-contour instruction regression to check bounds for
partial/full instances and default pins, with and without hints.
The regression fails before the fix. Full Meson: 272 passed, one skipped.

Assisted-by: OpenAI Codex
2026-10-22 06:56:14 -06:00
Behdad Esfahbod 3272df037c [subset] Allow CFF2 VariationStores larger than 65535 bytes (#6432)
OFF 2026 section 5.3.3.11.2 permits larger ItemVariationStores and
specifies a saturated length field of 65535. Partial CFF2 instancing
currently rejects these stores while serializing them.

Saturate the field while retaining the 32-bit offset size check.
Add a font with 200 referenced regions over 60 axes and exercise
partial instancing and extents at three locations. The test fails
before the fix because the output loses its CFF2 table.

Validation: full Meson suite, 272 passed and one skipped.

Assisted-by: OpenAI Codex
2026-10-21 19:59:08 -06:00
Behdad Esfahbod 2b6ffde1e5 [cff] Discard ignored Private DICT blend operands while loading CFF2 (#6431)
The ordinary CFF2 Private DICT parser ignores hint blend operators but
leaves their raw operands on its stack. Multiple valid blend groups can
therefore overflow the stack during font loading, making glyph extents
and drawing fail. The subset parser already discards these operands.

Clear ignored operands after each hint blend in the ordinary parser too.
Add a synthetic font with two seven-result groups over 40 regions and
check its glyph extents at default and non-default locations. Each group
fits the stack, but their raw operands together exceed its capacity.

The regression fails before the fix and passes after. The complete
Meson suite passes: 272 tests passed, one skipped.

Assisted-by: Codex <noreply@openai.com>
2026-10-21 19:58:41 -06:00
Behdad Esfahbod cb56bae961 [subset] Zero CFF2 instance bounds when no glyph contributes extents (#6430)
Instancing a CFF2 font with only empty outlines leaves the head bounds
accumulator at its inverted initialization sentinels. These are then
serialized as xMin=yMin=32767 and xMax=yMax=-32767.

Reset an empty accumulator to zero after collecting CFF2 extents. This
also provides a valid FontBBox if the instance is downgraded to CFF1.

Add a reproducible synthetic font and an API regression that fails before
the fix. The regression also checks preservation of the empty glyph's
advance and bearing. The complete Meson suite passes: 272 tests passed,
one skipped.

Assisted-by: Codex <noreply@openai.com>
2026-10-21 18:13:19 -06:00
nussaibah shaikh 6145d99262 Free the text copy on every hb_shape_justify() return path (#6422)
hb_shape_justify() copies the buffer text so it can reshape while
solving for the axis value, but only the solver path at the end
frees the copy. The three "nothing to solve" success returns
(default advance already in range, maximum expansion still short of
the target, maximum shrink still above it) and the three shaping
failure returns leak it, so ordinary line justification leaks one
text copy per call.

Free it with a scope guard right after the allocation, as the rest
of the tree does, and drop the explicit free at the end.

Reproduced with leaks --atExit on a plain experimental-API build:
four calls on Estedad-VF.ttf give four ROOT LEAKs at hb-shape.cc:319,
none with the fix. Add test-shape-justify.c covering all five paths
under the experimental-API test list so the asan-ubsan job runs it
under LeakSanitizer. The full ASan+UBSan Meson suite passes
(289 ok, 2 skipped).

Assisted-by: Claude
2026-10-20 11:25:59 -06:00
Behdad Esfahbod 0bfc7a9b16 [glyf] Charge composite offsets to the work budget (#6410)
* [glyf] Charge composite offsets to the work budget

Composite glyphs prepare component offsets before descending into
children. This work was not charged to the shared rendering budget,
including offsets for children later skipped by cycle detection.
Repeated preparation through COLR extents could time out the shaper.

Charge each offset before loading it and restore the scratch length
on failure. Add a cyclic-composite budget regression and the minimized
fuzzer testcase.

The full Meson suite passes (292 passed, one skipped). The reproducer
completes under ASan/UBSan in 17 seconds instead of timing out after
60 seconds. A failing-allocation variant passes 100 runs.

Fixes: https://oss-fuzz.com/testcase-detail/6193853460447232
Assisted-by: OpenAI Codex

* [glyf] Charge component preparation as traversal work

Component preparation parses records and updates scratch vectors, but
charging one unit per record still allows excessive work within the
shared budget. Use the existing 16-unit glyph traversal charge for
preparing a component, including children skipped by cycle detection.

Increase the cyclic-composite regression's budget so it also catches
the undercharged preparation path. The reproducer now takes about
1.1 seconds under ASan/UBSan and 0.03 seconds in the normal build.

Tested with the full Meson suite (292 passed, one skipped), 100
sanitizer reproducer runs, and 100 failing-allocation variant runs.

Assisted-by: OpenAI Codex
2026-10-18 19:54:45 -06:00
Behdad Esfahbod 54d71be605 [subset] Clamp overflowing COLRv1 variation values (#6408)
Unbounded variation deltas can overflow integer conversions while
instancing COLRv1 paints and clip boxes. Clamp coordinates, radii,
affine coefficients, and fixed-point values before narrowing them.
Keep affine base precision and existing alpha and clip rounding.

Add a generated font and regression checks for positive and negative
overflow in full and composed instances. Parenthesize the fixed-point
roundf argument so its template comma is safe for macro expansion.

Validation: meson compile -C build and meson test -C build pass
(292 tests passed, one skipped). The font regenerates identically.

Assisted-by: OpenAI Codex
2026-10-18 15:26:44 -06:00
nussaibah shaikh 47b18b6ebd [font] Don't read stale design coords in hb_font_set_variation() (#6402)
hb_font_set_variation() seeds its new design coords from the font's
existing ones for every axis of the current face, trusting an assert
that their lengths match. hb_font_set_face() keeps the font's
variation coords, which stay sized for the old face, so switching to
a face with more axes and then calling hb_font_set_variation() reads
past the old array: a heap-buffer-overflow read with NDEBUG, an
assertion failure otherwise.

Only reuse the existing design coords when their length matches the
current face; otherwise start from the defaults, as when none are set.

Reproduced the overflow under ASan with NDEBUG and the assertion
failure in the default build. Added a regression test in test-font.c
that fails without the fix. The full ASan+UBSan Meson suite passes.

Assisted-by: Claude
2026-10-16 12:18:00 -06:00
Behdad Esfahbod cb651c51d9 [ot] Ignore variation deltas at the default instance (#6401)
Use has_nonzero_coords when creating a shaping plan, and treat explicit
all-zero coordinates as an empty location in ItemVarStoreInstancer.
A constant GDEF delta then cannot change a condition at the default
instance, matching OFF section 7.1 and the condition's default field.

Keep the Boolean result in the stored int16 default when partial
instancing moves an oversized condition value into a private bias row.
Only the excess belongs in that row, since default instances ignore it.

Add a regression for empty versus explicit default plan keys and shaping
across default, varied, and default locations. Existing subset precision
tests cover the private bias and repeated instancing.

Validation: all 290 Meson test groups pass with experimental APIs enabled.

Assisted-by: Codex
2026-10-16 11:01:47 -06:00
Mar 5365d272d5 [font] Deprecate hb_font_set_face()
Changing the face now resets font funcs. Deprecate the setter in favor
of creating a new font with hb_font_create() and setting its properties.
Keep the exported symbol and move its declaration to hb-deprecated.h.

Document the deprecation in NEWS and the API section index. Guard the
face-setter tests with HB_DISABLE_DEPRECATED, and suppress expected
warnings from their deliberate use of the deprecated API.

The full ASan Meson suite passes (270 passed, 1 skipped). test-font also
builds and passes with HB_DISABLE_DEPRECATED. Its source passes Clang
-Werror checks both with and without deprecated APIs enabled.

Assisted-by: Claude
Assisted-by: Codex
2026-10-16 00:19:21 +03:00
Mar ef64f7ea8b [font] Reset font funcs in hb_font_set_face()
Font funcs and their data may hold pointers into the font's face.
hb_font_set_face() released the old face but kept those funcs, causing
stale lookups or a use-after-free when the last face reference was gone.

Release the font funcs and their data while the old face is still alive,
then install the default funcs for the new face. Preserve the other font
properties and document the callback reset in the API docs and NEWS.

Add regressions for OpenType lookups and custom font-data destruction.
Reproduced stale glyph lookup and the heap-use-after-free under ASan
before the fix. The full ASan Meson suite passes (270 passed, 1 skipped),
and the two regressions also pass with HB_FONT_FUNCS=ft.

Assisted-by: Claude
Assisted-by: Codex
2026-10-16 00:19:21 +03:00
nussaibah shaikh fe407340d5 Clamp transformed CFF2 blend deltas before int conversion (#6397)
When partially instancing a CFF2 font, the blend rewriters in
hb-subset-cff2.cc pass each old delta row through the region transform
and store the result with (int) round (transform_delta (...)).
transform_delta accumulates in double with no bound. Private DICT
operands can be BCD reals of any magnitude, so a StdVW blend delta of
1e12 yields about 3.7e11 at wght=300:600, and the double-to-int
conversion is undefined behavior (UBSan float-cast-overflow in
cff2_private_dict_blend_opset_t::rewrite_blends).

Saturate with hb_clamp_to<int>, as number_t::to_int already does.
The charstring blend rewriter uses the same expression and gets the
same clamp. Charstring operands are bounded by the 16.16 range, so
that site is not known to overflow in practice. Results that fit in
int are unchanged.

Add a regression test to test-instance-cff2 with a fixture generated
from AdobeVFPrototype.abc.otf. Under UBSAN_OPTIONS=halt_on_error=1 it
fails before the fix and passes after. The full Meson suite passes
under ASan+UBSan (290 ok).

Assisted-by: Claude
2026-10-15 11:16:49 -06:00
nussaibah shaikh 3fff90528d clamp variable advance before unsigned conversion (#6395)
get_advance_with_var_unscaled adds the HVAR/VVAR advance delta to the
base advance and returns the sum as unsigned. The delta from
ItemVariationStore::get_delta is an unbounded float, so an HVAR whose
item-variation store uses long-word (int32) deltas across several
regions that all peak at the axis extreme can make advance + roundf
(delta) exceed the unsigned range; converting that float to unsigned is
then undefined behavior (UBSan float-cast-overflow), and hb_max (0.0f,
NaN) would likewise pass NaN to the conversion. Reached from the public
hb_font_get_glyph_h_advance / v_advance on a variable font.

Clamp the accumulated value into the unsigned range with hb_clamp_to
before returning, matching the saturation already used for the
variation-derived glyph-extents arithmetic. Valid advances are
unchanged. The template is shared by hmtx/HVAR and vmtx/VVAR, so all
three advance sites are covered.

Add a regression test under test/api driving a crafted long-word HVAR;
it reports float-cast-overflow under the sanitizers job without the fix
and passes with it. The full meson test suite passes.
2026-10-14 10:51:09 -06:00
Behdad Esfahbod 2329384670 [subset] Preserve COLR sentinel-only variation maps (#6389)
COLR closure returned before planning delta-set index mappings when
there was no store or no live variation index. Variable paint and stop
serialization then failed to find their remapped bases, dropping COLR.

Remap explicit delta-set indices even when every entry is the
NO_VARIATION_INDEX sentinel. Keep variation-row planning conditional on
live rows. Cover NULL and empty stores with ordinary subsetting,
partial instancing of either axis, and full instancing.

Testing: meson test -C build passed 271 targets, with one skip.

Assisted-by: OpenAI Codex
2026-10-12 17:50:56 -06:00
Behdad Esfahbod e8ed626526 [subset] Preserve Fixed base precision in COLR affine values (#6384)
Instancing PaintVarTransform loses low Fixed bits when the stored base
is converted to float before adding its delta. This occurs at ordinary
translation values and even when the delta is zero.

Add the float delta to the precise stored integer in double precision,
then round to the target Fixed integer. Preserve the existing default
coordinate fast path.

Cover all six coefficients, signed and zero deltas, and direct and
composed instances in both axis orders at ordinary magnitudes. The
pre-fix library fails the translation regression. All 256 configured
Meson tests pass, and all 28 matrices match FontTools exactly in each
instancing order.

Assisted-by: Codex
2026-10-11 14:41:09 -06:00
Behdad Esfahbod 534f82e726 [subset] Preserve negative derived COLR radial gradients (#6387)
Reparameterize circles and color stops together when a derived radius
is negative. Preserve pad, repeat, reflect, and stable stop ordering.
Normalize constant gradients after a partial pin without creating
constant variation regions at the new default.

Allow fractional parameter shifts on the common lattice of the circle
coordinates and F2Dot14 stops. This preserves odd stop bits in ordinary
coordinate ranges that integer-only shifts incorrectly rejected.

Assisted-by: Codex
2026-10-11 14:37:21 -06:00
Behdad Esfahbod d5e4f22a13 [COLR] Round variable clip edges outwards (#6388)
Round minimum clip edges down and maximum edges up in font units.
Nearest rounding can shrink bounds and cut painted pixels.

Cover signed fractional deltas, default coordinates, rendering, and
full/composed instances in both axis orders at ordinary values.
All 256 configured Meson tests passed.

Assisted-by: Codex
2026-10-11 14:32:47 -06:00
Behdad Esfahbod fac913b1de [math] Preserve and apply shared GDEF variation indices (#6385)
MATH devices were evaluated against an empty variation store, and the
subsetter dropped them without folding deltas into the base values.
MATH users were also omitted when pruning GDEF's shared store.

Evaluate MATH VariationIndex devices with GDEF's store. Collect indices
from retained constants, glyph information, and assemblies, then fold
pinned deltas and remap residual devices during subsetting. Preserve
ordinary ppem device corrections and reject unrepresentable values.

Add a reproducible two-axis fixture covering every MathValueRecord
location, axis orders, full and partial instances, and glyph pruning.
All 255 configured tests pass; reduced-feature syntax checks pass.

Assisted-by: Codex
2026-10-11 00:41:07 -06:00
Behdad Esfahbod 173eeb59a3 [subset] Allow unchanged VARC axis range requests (#6371)
Assisted-by: Codex
2026-10-11 00:38:36 -06:00
Behdad Esfahbod 5c5172fcd2 [subset] Preserve zero-contour glyph instructions when instancing (#6369)
Zero-contour glyphs can contain instructions for phantom-point metrics.
Non-default instancing discarded them, while the empty-glyph branch
also bypassed ordinary hint removal.

Copy these instructions into owned compiled storage, and remove them
when hinting is dropped. Keep discarded .notdef outlines empty.

Add generated data and regressions for ordinary subsets, default pins,
partial and full instances, hint removal, and phantom-point advances.
The configured Meson suite passes: 253 tests and one skipped.

Assisted-by: Codex
2026-10-11 00:38:02 -06:00
Behdad Esfahbod 3b39c74c3a [subset] Preserve overflowing static COLRv1 scales (#6370)
Assisted-by: Codex
2026-10-11 00:37:22 -06:00
Behdad Esfahbodandartemkulyk bc1e757db1 [subset/CBDT] Share strike data without losing bitmaps on OOM (#6368)
Identical CBLC subtables can share exact image blocks instead of
copying the same CBDT bytes for every strike. Carry forward the sharing
implementation and expected font outputs from #6287.

A cache allocation failure previously discarded a strike without
setting a serializer error, so subsetting could succeed with no bitmap
strikes. Treat cache insertion as best-effort and stop further insertions
after a cache error. Propagate failures in the required temporary image
and offset buffers to the serializer instead of silently dropping data.

Add a regression that fails all three cache allocations in turn and
compares both strikes and every image byte with uncached output. It also
checks required allocation failures cannot silently discard a strike.
The cache regression fails against the original PR and passes here.

The full configured Meson suite passed: 289 tests, including all 224
CBDT subset cases. MSVC and native 32-bit builds were not run locally.


Assisted-by: OpenAI Codex

Co-authored-by: artemkulyk <artem.kulyk@gmail.com>
2026-10-11 00:36:18 -06:00
Behdad Esfahbod 94e9073251 [raster] Restore background and palette defaults on paint reset (#6361)
Paint reset omitted the background and palette, leaving settings from
the previous render despite its documented default-state guarantee.
Reset both fields and document that clear preserves these settings.

Add coverage for clear, reset, and rendering with a recycled image.
The regression fails before the fix. The full Meson suite passes:
290 tests passed and one existing test was skipped.

Fixes: https://github.com/harfbuzz/harfbuzz/issues/6356
Assisted-by: Codex
2026-10-10 18:32:30 -06:00
Behdad Esfahbod 199cae8b28 [buffer] Document message callback lifetime across reset (#6354)
Buffer reset has retained message callbacks since their introduction,
although its documentation promised a freshly created buffer state.
Clarify that callbacks, their associated data, and attached user data
survive reset. Document explicit callback removal and destruction.

Add a regression test for callback-directed lookup skipping after
clear/reset, restoration of ligatures after removal, and exactly-once
destruction on replacement, removal, and final buffer destruction.

Tested with meson test -C build: 287 passed, 1 skipped, 0 failed.
The API test also compiles without buffer messages or OT shaping.

Fixes: https://github.com/harfbuzz/harfbuzz/issues/6341
Assisted-by: OpenAI Codex
2026-10-10 16:58:18 -06:00
Behdad Esfahbod 1bf17d7295 [subset] Allow instancing axes unrelated to VARC (#6265)
Replace the blanket VARC instancing rejection with validation of the
axes referenced by retained components, variation regions, and nested
conditions. Remap those indices when unrelated axes are removed, while
keeping passthrough VARC incompatible with instancing.

Preserve component-internal variation data during avar2 instancing by
avoiding culling based on font-level reachable ranges. Add drawing
comparisons and rejection tests with reproducible fixtures, including
hidden component axes and non-default unrelated-axis pins.

Serialize sparse-region axis references using the revised VARC format.
Regenerate the fixtures without changing their logical VARC contents or
other table bytes, apart from the head checksum adjustment.

Validation: meson test -C build (283 passed); subset suite (130 passed);
C++11 compile checks with HB_NO_VAR and HB_NO_VAR_COMPOSITES.

Assisted-by: Codex
2026-10-10 04:04:32 -06:00