From fe05e48086be9ed685b8a6ca4af966660744bc0f Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 30 Mar 2019 15:06:25 -0700 Subject: [PATCH] [serialize] Add ran_out_of_room --- src/hb-serialize.hh | 8 +++++++- src/hb-subset.cc | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/hb-serialize.hh b/src/hb-serialize.hh index f5e4df521..679ae4ed6 100644 --- a/src/hb-serialize.hh +++ b/src/hb-serialize.hh @@ -51,6 +51,7 @@ struct hb_serialize_context_t void reset () { this->successful = true; + this->ran_out_of_room = false; this->head = this->start; this->debug_depth = 0; } @@ -111,7 +112,11 @@ struct hb_serialize_context_t template Type *allocate_size (unsigned int size) { - if (unlikely (!this->successful || this->end - this->head < ptrdiff_t (size))) { + if (unlikely (!this->successful)) return nullptr; + + if (this->end - this->head < ptrdiff_t (size)) + { + this->ran_out_of_room = true; this->successful = false; return nullptr; } @@ -190,6 +195,7 @@ struct hb_serialize_context_t unsigned int debug_depth; char *start, *end, *head; bool successful; + bool ran_out_of_room; }; diff --git a/src/hb-subset.cc b/src/hb-subset.cc index 135265fc1..b3f064697 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -83,7 +83,7 @@ _subset2 (hb_subset_plan_t *plan) hb_serialize_context_t serializer ((void *) buf, buf_size); hb_subset_context_t c (plan, &serializer); result = table->subset (&c); - if (serializer.in_error ()) + if (serializer.ran_out_of_room) { buf_size += (buf_size >> 1) + 32; DEBUG_MSG(SUBSET, nullptr, "OT::%c%c%c%c ran out of room; reallocating to %u bytes.", HB_UNTAG (tag), buf_size); @@ -94,6 +94,11 @@ _subset2 (hb_subset_plan_t *plan) } goto retry; } + if (serializer.in_error ()) + { + abort (); + } + if (result) { hb_blob_t *dest_blob = serializer.copy_blob ();