mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-20 06:21:16 +01:00
[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 <noreply@anthropic.com>
This commit is contained in:
1 parent
8f09a11184
commit
dae0a46b4d
1 file changed
+10
-1
+10
-1
@@ -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))
|
||||
|
||||
Reference in new issue
Block a user