[subset] bail out of subsetting if plan allocation fails.
diff --git a/src/hb-face.cc b/src/hb-face.cc
index 95d3fc2..7bde50d 100644
--- a/src/hb-face.cc
+++ b/src/hb-face.cc
@@ -721,7 +721,10 @@
return false;
hb_face_builder_data_t *data = (hb_face_builder_data_t *) face->user_data;
+
hb_face_builder_data_t::table_entry_t *entry = data->tables.push ();
+ if (data->tables.in_error())
+ return false;
entry->tag = tag;
entry->blob = hb_blob_reference (blob);
diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc
index b16f507..46b83e3 100644
--- a/src/hb-subset-plan.cc
+++ b/src/hb-subset-plan.cc
@@ -314,8 +314,12 @@
hb_subset_plan_create (hb_face_t *face,
hb_subset_input_t *input)
{
- hb_subset_plan_t *plan = hb_object_create<hb_subset_plan_t> ();
+ hb_subset_plan_t *plan;
+ if (unlikely (!(plan = hb_object_create<hb_subset_plan_t> ()))) {
+ return const_cast<hb_subset_plan_t *> (&Null (hb_subset_plan_t));
+ }
+ plan->successful = true;
plan->drop_hints = input->drop_hints;
plan->desubroutinize = input->desubroutinize;
plan->retain_gids = input->retain_gids;
diff --git a/src/hb-subset-plan.hh b/src/hb-subset-plan.hh
index 7a85b51..08b8f74 100644
--- a/src/hb-subset-plan.hh
+++ b/src/hb-subset-plan.hh
@@ -39,6 +39,7 @@
{
hb_object_header_t header;
+ bool successful : 1;
bool drop_hints : 1;
bool desubroutinize : 1;
bool retain_gids : 1;
@@ -89,6 +90,11 @@
public:
+ bool in_error () const
+ {
+ return !successful;
+ }
+
/*
* The set of input glyph ids which will be retained in the subset.
* Does NOT include ids kept due to retain_gids. You probably want to use
diff --git a/src/hb-subset.cc b/src/hb-subset.cc
index 3112739..8b77ecd 100644
--- a/src/hb-subset.cc
+++ b/src/hb-subset.cc
@@ -241,6 +241,8 @@
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 ()))
+ return hb_face_get_empty ();
hb_set_t tags_set;
bool success = true;
@@ -261,6 +263,7 @@
end:
hb_face_t *result = success ? hb_face_reference (plan->dest) : hb_face_get_empty ();
+
hb_subset_plan_destroy (plan);
return result;
}