From 4fc369ca3616cbbceac8ccefb38550f9a122c02b Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 21 Oct 2026 15:33:39 -0600 Subject: [PATCH] [subset] Preserve long CFF DICT byte spans Private DICT entries can accumulate several CFF2 blends before their final operator. An eight-bit byte count truncated these spans modulo 256 during serialization, producing malformed output. Use a full-width count and cover a 579-byte Private DICT with forty variation regions and fourteen blended BlueValues. Validation: full Meson suite, 272 passed and one skipped. Assisted-by: OpenAI Codex --- src/hb-cff-interp-common.hh | 8 ++--- test/api/fonts/cff2_long_private_blends.otf | Bin 0 -> 1632 bytes test/api/test-subset-cff2.c | 35 ++++++++++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 test/api/fonts/cff2_long_private_blends.otf diff --git a/src/hb-cff-interp-common.hh b/src/hb-cff-interp-common.hh index 1019b30c7..aacd1cd74 100644 --- a/src/hb-cff-interp-common.hh +++ b/src/hb-cff-interp-common.hh @@ -503,15 +503,15 @@ struct arg_stack_t : cff_stack_t /* an operator prefixed by its operands in a byte string */ struct op_str_t { - /* This used to have a hb_ubytes_t. Using a pointer and length - * in a particular order, saves 8 bytes in this struct and more - * in our parsed_cs_op_t subclass. */ + /* Borrow the encoded bytes. DICT entries with accumulated blends can + * exceed the length of an individual charstring token. */ const unsigned char *ptr = nullptr; op_code_t op = OpCode_Invalid; - uint8_t length = 0; + /* DICT entries can contain many blends before their final operator. */ + unsigned length = 0; }; /* base of OP_SERIALIZER */ diff --git a/test/api/fonts/cff2_long_private_blends.otf b/test/api/fonts/cff2_long_private_blends.otf new file mode 100644 index 0000000000000000000000000000000000000000..0609c1c6dcd0910a535a273008e9157a83ff96e3 GIT binary patch literal 1632 zcmeHH&ubGw6#ix>-6opaUx}$&?N(FuCKS;kMNNY_iIG|wZ+5k7b|JsmO*KdlJ$Ty+ zMJPRqc=6=HKf#+fK@hxn@F40{sF;)MH`Muym_xH;}|8d5iq??K`%=`o(()n6uZ$yfHZY6;ggytE*Gb*Lp{#QzVRzqTZ2KG}C2jP&@SsIsH&)NwF<9 z(1%#>@(%iMyIi2qE{C}ttO1J$>-e>W@=l$YBC4HIJk#PBV^e%Ciio)=ieCKm*Tj{s zF0hZQ%8u8Aelo2SOr+J0u>@zvaj2^sv^d+*X_LeyX4~?evhM_eSFg=G<&}!c&MX>c|Es+3T&>F$UNG(Xm+B}4*eMnUTdN~n#_LtKKy7**@#8$ zbyA^zP68L%{v~9vjGEya%ub9~WHOs^B=}YCWu69@w?PbH7$X>Ejij+38I0io4l=jn zIE*8hV5%l@6vvRo6prHr_me`1{(&$|Z-#vxREG#*w%@iVM#A-968@LJ`UbW#TkE?W f;Dd~*YZk0bgSDF?i{Dkhj%8Na2Fve0XSnbK*($M@ literal 0 HcmV?d00001 diff --git a/test/api/test-subset-cff2.c b/test/api/test-subset-cff2.c index c7a5c0611..6af90e79c 100644 --- a/test/api/test-subset-cff2.c +++ b/test/api/test-subset-cff2.c @@ -188,11 +188,46 @@ test_subset_cff2_iftb_requirements (void) } #endif +static void +test_subset_cff2_long_private_blends (void) +{ + hb_face_t *face = hb_test_open_font_file ("fonts/cff2_long_private_blends.otf"); + hb_blob_t *source = hb_face_reference_table (face, HB_TAG ('C','F','F','2')); + unsigned source_length; + const char *source_data = hb_blob_get_data (source, &source_length); + /* This fixture's Private DICT occupies [395, 974), including its final + * BlueValues operator. Its live stack never exceeds 513 operands. */ + const unsigned private_offset = 395, private_length = 579; + g_assert_cmpuint (private_offset + private_length, <=, source_length); + hb_subset_input_t *input = hb_subset_input_create_or_fail (); + hb_set_add_range (hb_subset_input_unicode_set (input), 'A', 'B'); + hb_face_t *subset = hb_subset_or_fail (face, input); + g_assert_nonnull (subset); + hb_blob_t *result = hb_face_reference_table (subset, HB_TAG ('C','F','F','2')); + unsigned length; + const char *data = hb_blob_get_data (result, &length); + gboolean found = FALSE; + for (unsigned i = 0; i + private_length <= length; i++) + if (!memcmp (source_data + private_offset, data + i, private_length)) + { + found = TRUE; + break; + } + g_assert_true (found); + hb_blob_destroy (result); + hb_face_destroy (subset); + hb_subset_input_destroy (input); + hb_blob_destroy (source); + hb_face_destroy (face); +} + int main (int argc, char **argv) { hb_test_init (&argc, &argv); + hb_test_add (test_subset_cff2_long_private_blends); + hb_test_add (test_subset_cff2_noop); hb_test_add (test_subset_cff2); hb_test_add (test_subset_cff2_strip_hints);