From dae0a46b4db6da2e5f233cea5dd52d4c8e53dc22 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 30 Oct 2026 15:28:07 -0600 Subject: [PATCH] [face-builder] Bound the summed table length before allocating the blob Table records of a font file may overlap, so the sum of the passed -through table lengths is not bounded by the size of the font: with HB_SUBSET_FLAGS_PASSTHROUGH_UNRECOGNIZED a 262 KB font of aliased records made _hb_face_builder_data_reference_blob() allocate and fill a ~4 GiB buffer, only for hb_blob_create() to refuse it. Accumulate face_length with hb_unsigned_add_overflows() and return nullptr as soon as the total reaches 1u<<31, the length hb_blob_create_or_fail() refuses, so the 2-4 GiB allocate-fill-free cycle no longer happens; the serializer's own bounds already prevented any overrun once the sum wrapped. Output for every input that succeeded before is unchanged. The endless retry that turned this into a hang is fixed in the companion commit (hb_face_reference_blob() no longer recurses into itself on the fallback builder). Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-NCMHVO1A. Co-Authored-By: Claude Opus 4.8 --- src/hb-face-builder.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/hb-face-builder.cc b/src/hb-face-builder.cc index d58b6b4fe..e4b232b8d 100644 --- a/src/hb-face-builder.cc +++ b/src/hb-face-builder.cc @@ -99,7 +99,16 @@ _hb_face_builder_data_reference_blob (hb_face_builder_data_t *data) unsigned int face_length = table_count * 16 + 12; for (auto info : data->tables.values()) - face_length += hb_ceil_to_4 (hb_blob_get_length (info.data)); + if (unlikely (hb_unsigned_add_overflows (face_length, + hb_ceil_to_4 (hb_blob_get_length (info.data)), + &face_length))) + return nullptr; + + /* hb_blob_create() refuses such a length; do not assemble the font + * only to throw it away. Tables referenced from a font file can + * overlap in it, so the sum is not bounded by the size of that file. */ + if (unlikely (face_length >= 1u << 31)) + return nullptr; char *buf = (char *) hb_malloc (face_length); if (unlikely (!buf))