Files
harfbuzz/test
Behdad EsfahbodandClaude Opus 4.8 51fae4098a [subset/CBDT] Bound image bytes copied out of the source table
IndexSubtableRecord::add_new_subtable() bounds-checks each retained
glyph's image block against the source CBDT table, but nothing
requires the blocks of different glyphs (or strikes) to be distinct
and nothing limits the total copied.  A format 3 offsetArray of
0, 65535, 0, 65535, ... makes every even glyph copy the same 64 KB,
so a ~186 KB font makes one hb_subset_or_fail() peak at ~3.8 GB and
emit a ~1.97 GB font.  The existing source_blob->length * 256 cap
covers only the serializer buffer holding the new CBLC, not the CBDT
side buffers.

Charge every block copied out of the source CBDT to a byte budget
that is proportional to the source table and shared across strikes,
and fail the strike when it runs out; the existing subset_size_table()
path then reverts that strike and continues.  The budget lives in
cbdt_dedup_context_t, which CBLC::subset already shares across every
strike, and is set to cbdt_length * HB_SUBSET_CBDT_MAX_COPY_FACTOR, a
new limit (64) in hb-limits.hh.  The charge is taken before the copy
into the per-strike buffer, so strikes that end up sharing data are
bounded as well, and it covers index formats 1/2/3 and overlapping
records, not only non-monotonic format 3 arrays.  The budget defaults
to unlimited, so the direct users of the struct (test-cbdt-cache) are
unaffected; a well-formed font copies each byte at most once per
strike, so only a font whose strikes reference the table more than 64
times over loses bitmaps.

This is distinct from the integer-overflow hardening of
_copy_data_to_cbdt() in PR #6485: that bounds the final append to
cbdt_prime, this bounds the overlap amplification before the copy.

Adds test_subset_cbdt_overlapping_images, which builds the format 3
shape above and asserts the output CBDT stays within the factor
(524292 > 65536 on the unpatched tree).  The api and subset suites
pass and the reproducer drops from 3767 MiB to 17 MiB.

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

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-30 14:50:11 -06:00
..