Files
harfbuzz/test/vector
Behdad EsfahbodandClaude Opus 4.8 a14c095e3f [vector] Refuse PDF indexed-PNG soft masks larger than the document cap
hb_pdf_build_indexed_smask() allocated and filled (width+1)*height and
width*height bytes straight from the attacker-controlled PNG IHDR, while
HB_VECTOR_MAX_DOCUMENT_SIZE was only consulted when the finished mask was
appended to the PDF object.  A ~1 MB sbix/CBDT font could thus make the
PDF backend inflate and un-filter up to a 4 GiB mask per painted glyph,
only to drop it afterwards.

The mask is emitted uncompressed into a document-capped hb_vector_buf_t,
so a mask larger than the cap can never be appended: reject it alongside
the existing 32-bit overflow guards in the builder (the same pattern as
the raster PNG decoder's HB_RASTER_MAX_BUFFER_SIZE check), which bounds
both allocations (raw_len = mask_len + height) before any work is done.

add_xobject_png_image() additionally skips registering and referencing
the SMask object when its buffer tripped the cap, so the output no longer
contains a dangling empty-stream object for an edge-case mask that fits
the builder but not the object with its header.  Masks that fit today are
unaffected.

A regression test in test/vector/test-vector-budget.c hand-rolls a zlib
stream for a 4097x4096 indexed PNG with tRNS, paints it to PDF, and
asserts the render succeeds without an /SMask.

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

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

Adding tests

test/vector validates hb-vector CLI output by comparing exact stdout with golden files.

Test file format (data/tests/*.tests)

Each non-empty, non-comment line has 4 semicolon-separated fields:

font-file;options;unicodes;expected-file
  • font-file: relative to the .tests file (or absolute path).
  • options: shell-split arguments passed to hb-vector.
  • unicodes: Unicode sequence, using shape-style codepoint format (for example U+0061,U+0062,U+0063).
  • expected-file: path to golden output, relative to the .tests file. This is also used as the TAP test name.

Example:

../../../api/fonts/Roboto-Regular.abc.ttf;--font-size=64;U+0061,U+0062,U+0063;../expected/basic/reuse-svg.svg

Running vector tests

In an in-tree build:

meson test -C build-default -v --suite vector

Updating expected output

Regenerate a golden file with the current hb-vector binary and replace the file under data/expected/.

Recording a new test case

Use record-test.sh:

./record-test.sh -o data/tests/basic.tests --test-name reuse-svg ../../build-default/util/hb-vector ../api/fonts/Roboto-Regular.abc.ttf --font-size=64 abc

It subsets the input font, verifies subset-vs-original rendering with hb-view, stores the subset font under ../fonts/<sha1>.ttf (relative to the target .tests file), writes expected output under ../expected/<tests-stem>/<test-name>.<ext> by default (unless --expected-dir or --expected-file is provided), and appends one test line to the target .tests file. hb-shape, hb-view, and hb-subset are resolved as sibling executables next to the provided hb-vector binary. The emitted test line uses Unicode codepoint input in the unicodes field.