* [instancer] Treat a zero-size pool allocation as success in gvar instancing hb_alloc_pool_t::alloc(0) legitimately returns nullptr while no shared chunk is open, but hb_vector_t::allocate_from_pool() took any nullptr as an allocation failure and flagged the (empty) vector with set_error(). The next allocate_from_pool() on it then tripped assert(!length && !allocated), aborting hb-subset during partial instancing of a crafted ~1 KB variable font whose retained glyph has more than 16,376 points (so no small request ever opens the shared chunk) and whose tuple is split by the requested axis range. Fix the root cause where the vector already special-cases zero-size requests on the heap path: a null result is a failure only when bytes were requested (size && !arrayZ). tuple_delta_t::copy_from() also discarded the results of its seven duplicate_vector_from_pool() calls, so a genuine pool failure during a tuple clone would reach the same assert (or silently drop gvar under NDEBUG); it now returns bool, change_tuple_var_axis_limit() marks out in error, and change_tuple_variations_axis_limits() fails instead of continuing. A regression test for the zero-size pool allocation is added to src/test-vector.cc. The attack font now instances to the same output as the control; test-vector and the subset suite pass. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-N0R68QRI. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * [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> * [vector] Reduce linear-gradient P2 anchor in the PDF backend The PDF paint backend drew COLRv1 linear gradients along the raw P0->P1 segment and marked the rotation anchor P2 as HB_UNUSED, writing the axial shading's /Coords straight from P0 and P1. For any gradient whose P2 - P0 is not perpendicular to P1 - P0 (how a font rotates or skews a gradient), the PDF put the colour stops in the wrong places, unlike the SVG, raster, GPU and cairo backends, which all call hb_paint_reduce_linear_anchors() first. Reduce the three COLR anchors to the two-point axis the same way and derive the gradient coordinates from the reduced axis. One change covers both the colour shading and the soft-mask shading, since both use the same gx0..gy1. Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-S7CCVVN0. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * [vector] Size PDF gradient soft masks to cover the painted area For a linear or radial COLRv1 gradient with a translucent stop, the PDF backend painted the alpha ramp through a luminosity soft mask whose Form XObject /BBox was the rectangle spanned by the gradient axis (linear) or the enclosing square of the outer circle (radial). An axial shading is not confined to its axis rectangle, and a radial shading with /Extend extends beyond its circles; the RGB fill relies on that. A form's /BBox clips everything it paints and the luminosity backdrop is black (mask 0) outside it, so the translucent gradient was masked out entirely for a horizontal or vertical axis (zero-area box) and cropped otherwise. Give both soft-mask forms a large box covering the whole painted area, as hb_pdf_paint_sweep_gradient() already does, instead of the axis or circle box. Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-3BXWX3QQ. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * [vector] Decline color_glyph in the SVG paint backend The SVG backend's color_glyph callback re-entered hb_font_paint_glyph() for every COLRv1 PaintColrGlyph, and each re-entry built a fresh COLR paint context whose HB_MAX_GRAPH_EDGE_COUNT and HB_MAX_NESTING_LEVEL counters started over. The limits therefore applied per nested glyph instead of per top-level glyph, so a DAG in which each level references the next one f times was walked f^levels times, letting a sub-2 KB font spin indefinitely; the same per-re-entry depth reset let a crafted font overflow a small thread stack. Return false, as hb-raster and the PDF backend do (and as the COLR and FreeType walkers expect), so the walker paints the nested glyph inline in the same context, where the existing decycler, nesting limit and edge limit bound the whole graph. The color_glyph_depth counter and active_color_glyphs set existed only to guard the re-entry, so they are dropped from hb_vector_paint_t and from create, destroy and clear. A regression test building a 30-level, 3-reference COLR chain in memory is added to test/vector/test-vector-budget.c for both SVG and PDF. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-YR4RMFWV. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * [vector] Make the document-size cap per document, not per buffer HB_VECTOR_MAX_DOCUMENT_SIZE was enforced in hb_vector_buf_t against the length of the one buffer being appended to, but both backends spread one document across many buffers, so the cap bounded each buffer and not the document. A few-KB COLRv1 font could exceed it by a large multiple: - SVG starts a fresh buffer per open paint group, so a chain of nested PaintComposite records keeps dozens of near-cap backdrop buffers alive at once (about 1 GB from a 1.3 KB font). An open group now inherits the bytes already held by the buffers it will be appended to, via a base member folded into would_overflow(), so base + length of every open group stays within the cap. - PDF keeps every object (functions, shadings, ExtGStates, images) in a buffer of its own with no running total, so one large gradient painted thousands of times produces millions of objects (gigabytes) that are only summed at render. add_object() now charges a running total against the same cap with a sticky overflow flag; the image and gradient callbacks stop when res->in_error(), and render returns NULL in that state because the content stream would refer to dropped objects. hb_vector_buf_t and hb_pdf_resources_t are internal, so there is no API or ABI change; documents that fit under the cap are unchanged. Regression tests are added to test/vector/test-vector-budget.c. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-C20MD9VR. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <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.