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 000000000..0609c1c6d Binary files /dev/null and b/test/api/fonts/cff2_long_private_blends.otf differ 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);