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>