From d653f4b6f5de3bdeecc75e5de99469e2c34af4e1 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 4 Jun 2026 22:29:26 +0200 Subject: [PATCH] [ot] Hide maxp/MAXP selection behind maxp loader Expose only face->table.maxp to clients and let its accelerator choose MAXP before falling back to maxp. This keeps the uppercase table as a tagged concrete type for subsetting while avoiding a second client-facing face-table slot. Use a sanitizer context with num_glyphs set to zero, matching core table loading, so reading maxp/MAXP does not recurse back through hb_face_t::get_num_glyphs(). Tested with meson test -C build and a no-beyond64k fuzzer target build. Assisted-by: OpenAI Codex --- src/hb-ot-face-table-list.hh | 5 +--- src/hb-ot-maxp-table.hh | 44 ++++++++++++++++++++++++++++++++++++ src/hb-static.cc | 4 ---- 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/src/hb-ot-face-table-list.hh b/src/hb-ot-face-table-list.hh index 6f030d46b..c8ce88967 100644 --- a/src/hb-ot-face-table-list.hh +++ b/src/hb-ot-face-table-list.hh @@ -52,10 +52,7 @@ /* OpenType fundamentals. */ HB_OT_CORE_TABLE (OT, head) -HB_OT_CORE_TABLE (OT, maxp) -#ifndef HB_NO_BEYOND_64K -HB_OT_CORE_TABLE (OT, MAXP) -#endif +HB_OT_ACCELERATOR (OT, maxp) #if !defined(HB_NO_FACE_COLLECT_UNICODES) || !defined(HB_NO_OT_FONT) HB_OT_ACCELERATOR (OT, cmap) #endif diff --git a/src/hb-ot-maxp-table.hh b/src/hb-ot-maxp-table.hh index 709dfd964..6c3df81b8 100644 --- a/src/hb-ot-maxp-table.hh +++ b/src/hb-ot-maxp-table.hh @@ -162,6 +162,50 @@ struct MAXP : maxp_MAXP static constexpr hb_tag_t tableTag = HB_OT_TAG_MAXP; }; +struct maxp_accelerator_t +{ + maxp_accelerator_t () + { + blob = hb_blob_get_empty (); + numGlyphs = 0; + } + + maxp_accelerator_t (hb_face_t *face) : maxp_accelerator_t () + { +#ifndef HB_NO_BEYOND_64K + if (init_table (face)) + return; +#endif + + init_table (face); + } + + ~maxp_accelerator_t () { hb_blob_destroy (blob); } + + unsigned int get_num_glyphs () const { return numGlyphs; } + hb_blob_t *get_blob () const { return blob; } + + private: + template + bool init_table (hb_face_t *face) + { + hb_sanitize_context_t c; + c.set_num_glyphs (0); + hb_blob_ptr_t table = c.reference_table
(face); + bool ret = table.get_length (); + if (ret) + { + blob = hb_blob_reference (table.get_blob ()); + numGlyphs = table->get_num_glyphs (); + } + table.destroy (); + return ret; + } + + hb_blob_t *blob; + unsigned int numGlyphs; +}; + } /* namespace OT */ diff --git a/src/hb-static.cc b/src/hb-static.cc index c38a4487d..9867d3407 100644 --- a/src/hb-static.cc +++ b/src/hb-static.cc @@ -72,10 +72,6 @@ const unsigned char *endchar_str = static_endchar_str; static inline unsigned load_num_glyphs_from_maxp (const hb_face_t *face) { -#ifndef HB_NO_BEYOND_64K - if (face->table.MAXP) - return face->table.MAXP->get_num_glyphs (); -#endif return face->table.maxp->get_num_glyphs (); }