[subset] Fix subset_offset_array adding unused space to serializer.

ArrayOf.serialize_append allocates space for the new item, but ArrayOf.pop() does not recover the allocated space. So in the case where the revert path was entered the extra space added by serialize_append gets left in the serialization buffer. This moves the snapshot to before ArrayOf.serialize_append is called so that revert cleans up the buffer extend.
This commit is contained in:
Garret Rieger 2021-09-22 14:15:55 -07:00
parent 8c5c81746d
commit c2cc566c9d
23 changed files with 5 additions and 5 deletions

View File

@ -237,9 +237,9 @@ struct subset_offset_array_t
template <typename T> template <typename T>
bool operator () (T&& offset) bool operator () (T&& offset)
{ {
auto snap = subset_context->serializer->snapshot ();
auto *o = out.serialize_append (subset_context->serializer); auto *o = out.serialize_append (subset_context->serializer);
if (unlikely (!o)) return false; if (unlikely (!o)) return false;
auto snap = subset_context->serializer->snapshot ();
bool ret = o->serialize_subset (subset_context, offset, base); bool ret = o->serialize_subset (subset_context, offset, base);
if (!ret) if (!ret)
{ {
@ -268,9 +268,9 @@ struct subset_offset_array_arg_t
template <typename T> template <typename T>
bool operator () (T&& offset) bool operator () (T&& offset)
{ {
auto snap = subset_context->serializer->snapshot ();
auto *o = out.serialize_append (subset_context->serializer); auto *o = out.serialize_append (subset_context->serializer);
if (unlikely (!o)) return false; if (unlikely (!o)) return false;
auto snap = subset_context->serializer->snapshot ();
bool ret = o->serialize_subset (subset_context, offset, base, arg); bool ret = o->serialize_subset (subset_context, offset, base, arg);
if (!ret) if (!ret)
{ {

View File

@ -1386,9 +1386,9 @@ struct PairPosFormat1
| hb_filter (glyphset, hb_first) | hb_filter (glyphset, hb_first)
| hb_filter ([this, c, out] (const Offset16To<PairSet>& _) | hb_filter ([this, c, out] (const Offset16To<PairSet>& _)
{ {
auto snap = c->serializer->snapshot ();
auto *o = out->pairSet.serialize_append (c->serializer); auto *o = out->pairSet.serialize_append (c->serializer);
if (unlikely (!o)) return false; if (unlikely (!o)) return false;
auto snap = c->serializer->snapshot ();
bool ret = o->serialize_subset (c, _, this, valueFormat, out->valueFormat); bool ret = o->serialize_subset (c, _, this, valueFormat, out->valueFormat);
if (!ret) if (!ret)
{ {

View File

@ -1752,10 +1752,10 @@ struct RuleSet
for (const Offset16To<Rule>& _ : rule) for (const Offset16To<Rule>& _ : rule)
{ {
if (!_) continue; if (!_) continue;
auto o_snap = c->serializer->snapshot ();
auto *o = out->rule.serialize_append (c->serializer); auto *o = out->rule.serialize_append (c->serializer);
if (unlikely (!o)) continue; if (unlikely (!o)) continue;
auto o_snap = c->serializer->snapshot ();
if (!o->serialize_subset (c, _, this, lookup_map, klass_map)) if (!o->serialize_subset (c, _, this, lookup_map, klass_map))
{ {
out->rule.pop (); out->rule.pop ();
@ -2724,10 +2724,10 @@ struct ChainRuleSet
for (const Offset16To<ChainRule>& _ : rule) for (const Offset16To<ChainRule>& _ : rule)
{ {
if (!_) continue; if (!_) continue;
auto o_snap = c->serializer->snapshot ();
auto *o = out->rule.serialize_append (c->serializer); auto *o = out->rule.serialize_append (c->serializer);
if (unlikely (!o)) continue; if (unlikely (!o)) continue;
auto o_snap = c->serializer->snapshot ();
if (!o->serialize_subset (c, _, this, if (!o->serialize_subset (c, _, this,
lookup_map, lookup_map,
backtrack_klass_map, backtrack_klass_map,