[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
This commit is contained in:
Behdad Esfahbod committed 2026-06-05 12:34:52 +02:00
1 parent c47f89d42b
commit d653f4b6f5
3 files changed
+45 -8

No files matched your search

+1 -4
View File
@@ -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
+44
View File
@@ -162,6 +162,50 @@ struct MAXP : maxp_MAXP<Layout::MediumTypes>
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<MAXP> (face))
return;
#endif
init_table<maxp> (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 <typename Table>
bool init_table (hb_face_t *face)
{
hb_sanitize_context_t c;
c.set_num_glyphs (0);
hb_blob_ptr_t<Table> table = c.reference_table<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 */
-4
View File
@@ -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 ();
}