mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-27 16:49:42 +01:00
[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
This commit is contained in:
1 parent
646b0d8de9
commit
4fc369ca36
3 files changed
+39
-4
No files matched your search
@@ -503,15 +503,15 @@ struct arg_stack_t : cff_stack_t<ARG, 513>
|
||||
/* 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 */
|
||||
|
||||
Binary file not shown.
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user