The vector work budget charged both outline traversal and serialized output bytes, and left embedded bitmaps entirely uncharged -- so a COLR walk with many sweep-gradient or image layers could emit output that the outline budget never sees, bounded only by the structural per-node caps times the node count. Bound the output with a flat document-size cap instead: hb_vector_buf_t refuses to grow past HB_VECTOR_MAX_DOCUMENT_SIZE (16 MB) and folds that into in_error(), so every emission site that already checks it -- path commands, gradient meshes -- stops cleanly, and image embedding is bounded for the first time. clear() resets the sticky flag so a context reused across renders (the documented clear -> paint -> render loop) recovers after one over-cap glyph. vector is one glyph per context, so a flat cap suffices; SVG's whole document and PDF's (assembled through the same hb_vector_buf_t) share it. With output bounded structurally, the work budget goes back to pure outline traversal: drop the per-command byte charge and the sweep-patch charge so it no longer conflates two different resources. It is still needed on its own -- a CFF charstring can do a lot of work while emitting little output. Once the cap trips, remaining appends are dropped, so a truncated document is malformed; render returns it (or null) rather than looping to build gigabytes, which is the point. Add a regression test that paints an oversized image and confirms the document stays bounded and the context recovers on reuse; it fails if the cap is removed. Tests: meson test -C build (275/275 passed); the vector COLR regression seed completes in 0.85s. Assisted-by: Claude <noreply@anthropic.com>
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.testsfile (or absolute path).options: shell-split arguments passed tohb-vector.unicodes: Unicode sequence, using shape-style codepoint format (for exampleU+0061,U+0062,U+0063).expected-file: path to golden output, relative to the.testsfile. 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.