mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-24 00:11:14 +01:00
hb_cairo_init_scaled_font() must hand exactly one reference of the hb_font_t to the cairo_scaled_font_t. For a face-based font face (hb_cairo_font_face_create_for_face()) it creates the font with a reference count of 1, but then still called hb_font_reference() before attaching it, so the creating reference was never released. Every finalized scaled font therefore leaked an hb_font_t, pinning its hb_face_t, the font blob and the accelerators until the process exits. Cairo finalizes scaled fonts during normal operation once its cache fills, so the leak accumulates as content selects distinct sizes, transforms or font options. Take the extra reference only in the branch where the font is the shared one owned by the cairo font face (the font-based constructor), and transfer the freshly created font as-is. The set_user_data result is now checked and the font released on failure, matching the budget/color-cache idiom a few lines below and the font-face constructors in the same file. A callback installed with hb_cairo_font_face_set_font_init_func() that returns a different font keeps its historical behavior: the returned font is referenced rather than assumed to transfer ownership, so no in-tree contract changes and no caller can turn into a use-after-free. hb-view uses the font-based constructor and was unaffected. A regression test in test/api/test-cairo.c registers a face destroy notifier, draws through a face-based font face, flushes cairo's scaled-font cache and asserts the face was destroyed; it fails on the unpatched library and passes with the fix. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-BAUN9JN4. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>