Check for alloc failures on the gsub/gpos_langsys maps in subset plan creation.

This commit is contained in:
Garret Rieger 2021-03-25 11:39:57 -07:00
parent 29708e959a
commit 3c8273ab68
2 changed files with 30 additions and 18 deletions

View File

@ -373,16 +373,20 @@ hb_subset_plan_create (hb_face_t *face,
plan->gsub_lookups = hb_map_create ();
plan->gpos_lookups = hb_map_create ();
plan->gsub_langsys = hb_object_create<script_langsys_map> ();
plan->gsub_langsys->init_shallow ();
if (plan->check_success (plan->gsub_langsys = hb_object_create<script_langsys_map> ()))
plan->gsub_langsys->init_shallow ();
if (plan->check_success (plan->gpos_langsys = hb_object_create<script_langsys_map> ()))
plan->gpos_langsys->init_shallow ();
plan->gpos_langsys = hb_object_create<script_langsys_map> ();
plan->gpos_langsys->init_shallow ();
plan->gsub_features = hb_map_create ();
plan->gpos_features = hb_map_create ();
plan->layout_variation_indices = hb_set_create ();
plan->layout_variation_idx_map = hb_map_create ();
if (plan->in_error ()) {
return plan;
}
_populate_gids_to_retain (plan,
input->unicodes,
input->glyphs,
@ -429,19 +433,25 @@ hb_subset_plan_destroy (hb_subset_plan_t *plan)
hb_set_destroy (plan->layout_variation_indices);
hb_map_destroy (plan->layout_variation_idx_map);
for (auto _ : plan->gsub_langsys->iter ())
hb_set_destroy (_.second);
if (plan->gsub_langsys)
{
for (auto _ : plan->gsub_langsys->iter ())
hb_set_destroy (_.second);
hb_object_destroy (plan->gsub_langsys);
plan->gsub_langsys->fini_shallow ();
free (plan->gsub_langsys);
hb_object_destroy (plan->gsub_langsys);
plan->gsub_langsys->fini_shallow ();
free (plan->gsub_langsys);
}
for (auto _ : plan->gpos_langsys->iter ())
hb_set_destroy (_.second);
if (plan->gpos_langsys)
{
for (auto _ : plan->gpos_langsys->iter ())
hb_set_destroy (_.second);
hb_object_destroy (plan->gpos_langsys);
plan->gpos_langsys->fini_shallow ();
free (plan->gpos_langsys);
hb_object_destroy (plan->gpos_langsys);
plan->gpos_langsys->fini_shallow ();
free (plan->gpos_langsys);
}
free (plan);
}

View File

@ -302,8 +302,10 @@ hb_subset (hb_face_t *source, hb_subset_input_t *input)
if (unlikely (!input || !source)) return hb_face_get_empty ();
hb_subset_plan_t *plan = hb_subset_plan_create (source, input);
if (unlikely (plan->in_error ()))
if (unlikely (plan->in_error ())) {
hb_subset_plan_destroy (plan);
return hb_face_get_empty ();
}
hb_set_t tags_set;
bool success = true;