From 7052cd343ed0f8ce8bdbf2d72a0bc8030e2b734b Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 8 Jul 2026 00:46:20 -0600 Subject: [PATCH] [GSUB] Fix NULL-deref in SingleSubst get_glyph_alternates hb_ot_layout_lookup_get_glyph_alternates() documents its alternate_glyphs output as nullable, and the AlternateSubst path was fixed in the previous commit. The Single-substitution fallback paths (SingleSubstFormat1 and SingleSubstFormat2, used when the queried lookup is a single-substitution) had the same defect: they gated the write on if (alternate_count && *alternate_count) and then did *alternate_glyphs = glyph_id without checking alternate_glyphs. Passing a NULL alternate_glyphs with a non-NULL, non-zero count on a covered glyph therefore wrote through NULL and crashed. Also require alternate_glyphs to be non-NULL before storing. Fixes: GHSA-v5mv-8hhw-vff8 Co-Authored-By: Claude Opus 4.8 (1M context) --- src/OT/Layout/GSUB/SingleSubstFormat1.hh | 2 +- src/OT/Layout/GSUB/SingleSubstFormat2.hh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OT/Layout/GSUB/SingleSubstFormat1.hh b/src/OT/Layout/GSUB/SingleSubstFormat1.hh index 1cd3f9d9c..2c2733d4c 100644 --- a/src/OT/Layout/GSUB/SingleSubstFormat1.hh +++ b/src/OT/Layout/GSUB/SingleSubstFormat1.hh @@ -109,7 +109,7 @@ struct SingleSubstFormat1_3 return 0; } - if (alternate_count && *alternate_count) + if (alternate_count && *alternate_count && alternate_glyphs) { hb_codepoint_t d = deltaGlyphID; hb_codepoint_t mask = get_mask (); diff --git a/src/OT/Layout/GSUB/SingleSubstFormat2.hh b/src/OT/Layout/GSUB/SingleSubstFormat2.hh index 4c98f05ae..8e6df7d63 100644 --- a/src/OT/Layout/GSUB/SingleSubstFormat2.hh +++ b/src/OT/Layout/GSUB/SingleSubstFormat2.hh @@ -89,7 +89,7 @@ struct SingleSubstFormat2_4 return 0; } - if (alternate_count && *alternate_count) + if (alternate_count && *alternate_count && alternate_glyphs) { glyph_id = substitute[index];