mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-20 14:31:10 +01:00
[subset] Guard against null glyf blob in contour-point budget
get_instance_glyphs_contour_points() sizes its op budget from the source glyf table length. When head.glyphDataFormat (or indexToLocFormat) is out of range the glyf accelerator is disabled and reference_glyf_table() returns no blob, so hb_blob_get_length() then dereferenced a null pointer and crashed during partial instancing. Take the length only when the blob is non-null. Add a regression test that builds a variable font with an invalid glyphDataFormat and plans a partial instance. Reported by Anthropic's OSS Scanner. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
69680c7b4c
commit
10fa66cdd4
2 files changed
+58
-1
No files matched your search
@@ -845,7 +845,7 @@ get_instance_glyphs_contour_points (hb_subset_plan_t *plan)
|
||||
* count alone does not bound it. */
|
||||
hb_blob_t *glyf_blob = glyf.reference_glyf_table ();
|
||||
int64_t budget = hb_max (HB_BUDGET_SUBSET_CONTOUR_POINTS,
|
||||
(int64_t) hb_blob_get_length (glyf_blob));
|
||||
(int64_t) (glyf_blob ? hb_blob_get_length (glyf_blob) : 0));
|
||||
hb_blob_destroy (glyf_blob);
|
||||
|
||||
for (auto &_ : plan->new_to_old_gid_list)
|
||||
|
||||
@@ -403,6 +403,62 @@ test_subset_gvar_shared_glyph_data (void)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_subset_gvar_invalid_glyf_format (void)
|
||||
{
|
||||
/* head.glyphDataFormat > 1 disables the glyf accelerator, so
|
||||
* reference_glyf_table () hands back no blob. Partial instancing (only
|
||||
* one of the two axes pinned) still enters
|
||||
* get_instance_glyphs_contour_points (), which must not take the length of
|
||||
* that null blob. */
|
||||
static char head[54] = {
|
||||
0, 1, 0, 0, /* version 1.0 */
|
||||
0, 0, 0, 0, /* fontRevision */
|
||||
0, 0, 0, 0, /* checksumAdjustment */
|
||||
0x5F, 0x0F, 0x3C, (char) 0xF5, /* magicNumber */
|
||||
0, 0, /* flags */
|
||||
0x03, (char) 0xE8, /* unitsPerEm */
|
||||
/* ... indexToLocFormat and glyphDataFormat set below */
|
||||
};
|
||||
static const char maxp[] = {
|
||||
0, 0, 0x50, 0, /* version 0.5 */
|
||||
0, 2, /* numGlyphs */
|
||||
};
|
||||
static const char fvar[] = {
|
||||
0, 1, 0, 0, /* version 1.0 */
|
||||
0, 16, /* axesArrayOffset */
|
||||
0, 2, /* reserved */
|
||||
0, 2, /* axisCount */
|
||||
0, 20, /* axisSize */
|
||||
0, 0, /* instanceCount */
|
||||
0, 12, /* instanceSize */
|
||||
'w', 'g', 'h', 't', 0, 100, 0, 0, 1, (char) 144, 0, 0, 3, (char) 132, 0, 0, 0, 0, 1, 0,
|
||||
'w', 'd', 't', 'h', 0, 50, 0, 0, 0, 100, 0, 0, 0, (char) 200, 0, 0, 0, 0, 1, 1,
|
||||
};
|
||||
static const char loca[] = { 0, 0, 0, 0, 0, 0 }; /* short loca, 2 empty glyphs */
|
||||
static const char glyf[] = { 0 };
|
||||
|
||||
head[51] = 0; /* indexToLocFormat: short */
|
||||
head[53] = 2; /* glyphDataFormat: invalid (> 1) */
|
||||
|
||||
hb_face_t *face = hb_face_builder_create ();
|
||||
HB_FACE_ADD_TABLE (face, "head", head);
|
||||
HB_FACE_ADD_TABLE (face, "maxp", maxp);
|
||||
HB_FACE_ADD_TABLE (face, "fvar", fvar);
|
||||
HB_FACE_ADD_TABLE (face, "loca", loca);
|
||||
HB_FACE_ADD_TABLE (face, "glyf", glyf);
|
||||
|
||||
hb_subset_input_t *input = hb_subset_input_create_or_fail ();
|
||||
hb_set_add_range (hb_subset_input_glyph_set (input), 0, 1);
|
||||
g_assert_true (hb_subset_input_pin_axis_location (input, face, HB_TAG ('w','g','h','t'), 500));
|
||||
|
||||
/* The point is that this does not crash. */
|
||||
hb_subset_plan_t *plan = hb_subset_plan_create_or_fail (face, input);
|
||||
hb_subset_plan_destroy (plan);
|
||||
hb_subset_input_destroy (input);
|
||||
hb_face_destroy (face);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
@@ -414,6 +470,7 @@ main (int argc, char **argv)
|
||||
hb_test_add (test_subset_gvar);
|
||||
hb_test_add (test_subset_gvar_retaingids);
|
||||
hb_test_add (test_subset_gvar_shared_glyph_data);
|
||||
hb_test_add (test_subset_gvar_invalid_glyf_format);
|
||||
#ifndef HB_NO_BEYOND_64K
|
||||
hb_test_add (test_subset_GVAR_header);
|
||||
hb_test_add (test_subset_GVAR_all_axes_pinned);
|
||||
|
||||
Reference in new issue
Block a user