From 2aae9010bd890eadabc2b07b41b23959f4438db0 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Tue, 18 Aug 2026 01:28:02 +0000 Subject: [PATCH] Handle allocation failure during glyph_to_sid_map. --- src/hb-ot-cff1-table.hh | 6 ++++-- src/hb-subset-cff1.cc | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/hb-ot-cff1-table.hh b/src/hb-ot-cff1-table.hh index 563e39072..79f265050 100644 --- a/src/hb-ot-cff1-table.hh +++ b/src/hb-ot-cff1-table.hh @@ -327,7 +327,7 @@ struct Charset0 void collect_glyph_to_sid_map (glyph_to_sid_map_t *mapping, unsigned int num_glyphs) const { - mapping->resize_dirty (num_glyphs); + if (!mapping->resize_dirty (num_glyphs)) return; for (hb_codepoint_t gid = 1; gid < num_glyphs; gid++) mapping->arrayZ[gid] = {sids[gid - 1], gid}; } @@ -427,10 +427,12 @@ struct Charset1_2 { void collect_glyph_to_sid_map (glyph_to_sid_map_t *mapping, unsigned int num_glyphs) const { - mapping->resize_dirty (num_glyphs); + if (!mapping->resize_dirty (num_glyphs)) return; + hb_codepoint_t gid = 1; if (gid >= num_glyphs) return; + for (unsigned i = 0;; i++) { hb_codepoint_t sid = ranges[i].first; diff --git a/src/hb-subset-cff1.cc b/src/hb-subset-cff1.cc index 4c2da6b40..fee2fb933 100644 --- a/src/hb-subset-cff1.cc +++ b/src/hb-subset-cff1.cc @@ -518,6 +518,7 @@ struct cff1_subset_plan glyph_to_sid_map_t *glyph_to_sid_map = acc.cff_accelerator ? acc.cff_accelerator->glyph_to_sid_map.get_acquire () : nullptr; + bool created_map = false; if (!glyph_to_sid_map && acc.cff_accelerator) { @@ -525,6 +526,12 @@ struct cff1_subset_plan glyph_to_sid_map = acc.create_glyph_to_sid_map (); } + if (!glyph_to_sid_map || glyph_to_sid_map->in_error ()) + { + glyph_to_sid_map = nullptr; + created_map = false; + } + auto it = hb_iter (plan->new_to_old_gid_list); if (it->first == 0) it++; auto _ = *it;