Read three keys for what they are, not for one shape each - #105
Merged
Merged
Conversation
Three keys were read without checking they are there, each in a different entry shape than the read assumed. TTFontFile's 'locl' pre-pass and its joining-form branch both read ['replace'] on every entry carrying the tag, including the contextual entries that keep their replacements in ['rules'] and have no such key. Both now tell the two apart, as the loop between them already did. A joining form can be a Multiple Substitution - the dotless form of a letter and the dots to draw under it - and the whole replacement was pushed into the Private Use Area list as if it named one glyph. hexdec() raised PHP 8's invalid-characters deprecation on it and returned a number far outside E000-F8FF, so every glyph it named was dropped. The three places that collect these glyphs now share one method, which splits. Otl::GSUBsubstitute() carries a category onto the glyphs a substitution makes for the Indic, Khmer, Sinhala and Myanmar shapers, and had no branch for the South East Asian one, so a Tai Tham cluster that reaches the reorderer through a 'ccmp' ligature was read for a ['sea_category'] it had not got. What the read turns on is that the last glyph of the cluster came out of that pass, not how long the cluster is - Lanna Alif warns on a cluster of two and Noto Sans Tai Tham on one. Nothing moves on a page. The parser output is identical over 104 fonts but for rtlPUAstr on the two Arabic fonts, which each gain one PUA codepoint that mPDF's Arabic shaper cannot reach; the Tai Tham snapshot is byte-identical to the one the code before this writes. Test fonts: NotoSansDevanagari-ContextualLocl-Subset (4 glyphs of Noto Sans Devanagari 2.005, OFL 1.1) and NotoSansArabic-MultipleForm-Subset (8 glyphs of Noto Sans Arabic 2.012, OFL 1.1). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
jakejackson1
force-pushed
the
fix/104-unguarded-reads
branch
from
September 14, 2026 22:43
0d0d68e to
d5a8721
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #104.
The three reads that remained after #95, #96 and #98: each a key read without checking it is there, each in a different file. None is reached by anything in
tests/data/ttforpackages/today — they were found rendering the currentgoogle/fontsreleases undererror_reporting(E_ALL), where a diagnostic is a failed render and a family that cannot render atuseOTL => 0xFFships at0instead.1. A contextual
loclentry has no top-levelreplaceThe pre-pass that indexes single-glyph
loclsubstitutions read['replace']on every entry taggedlocl. A contextual entry keeps its replacements in['rules']and has no such key. The loop twenty lines below it already tells the two apart —elseif (!isset($v['context']))— and the pre-pass now does too.Nothing is indexed either way:
nullwas discarded by the same test that discards a replacement of the wrong length. One warning per font load, for each of Noto Sans Devanagari and Noto Sans Bengali.2. A joining form can be more than one glyph
$rtlpua[] = $subtook['replace']for one glyph. A joining form can be a Multiple Substitution — the dotless form of a letter and the dots to draw under it — and the whole string went in as if it were one.hexdec()raised PHP 8's invalid-characters deprecation on it, 30 times per load of Noto Sans Arabic, and returned a number far outsideE000-F8FF, so every glyph named in it was dropped.The three sites that collect these glyphs now share one method, which splits. The list is what
magic_reverse_dirreads to know which PUA codepoints are right-to-left, and a mark only ever drawn as part of a joining form belongs in it.This is the one behaviour any of the three moves. Over 104 fonts —
packages/,tests/data/ttfand the current releases of the five families the issue names — the parser output is identical but forrtlPUAstron the two Arabic fonts, which each gain one PUA codepoint. Neither reaches a page:Arabic::glyphs()returns one glyph for one character, so mPDF's Arabic shaper cannot apply a multi-glyph joining form at all. That limitation is left alone here.3. A glyph substituted before the SEA reordering has no category
The South East Asian shaper categorises every character, groups them into clusters, then applies
loclandccmpbefore reordering each cluster — and the reorderer reads['sea_category']on the last glyph of a broken cluster.GSUBsubstitute()already carries a category onto the glyphs it makes, for the Indic, Khmer, Sinhala and Myanmar shapers. The SEA shaper never had a branch. Lanna Alif'sccmpligates a Sakot with the consonant after it, and a Sakot with nothing in front of it is a broken cluster, so the ligature is exactly what the reorderer asks about.On the trigger, since a comment on the issue narrowed this half to a cluster of one element: that holds for Noto Sans Tai Tham and is not the rule. Lanna Alif warns on a cluster of two. The difference is U+25CC — Noto Sans Tai Tham has none, so nothing is inserted ahead of the ligature and the cluster is the ligature alone; Lanna Alif has one, and the cluster is the dotted circle then the ligature. Both read
$end - 1and both find the glyph thelocl/ccmppass made. What the read turns on is that the last element came out of that pass, not how many elements there are — so a guard placed on the length would cover only one of the two fonts.The comment's 21-token split reproduces exactly against
notosanstaitham-R.ttf: the 7 tokens it lists warn, the 14 do not,1A64 1A62is clean and1A64 1A62 1A62warns. All 21 are clean with this fix, and the drawn text is identical before and after it.Its stronger point stands, and is the real cost: those seven tokens are shaped, so a font that falls back to
useOTL => 0loses that work.1A73 1A62drawsE225at0xFFand two unshaped characters at0. The magnitude is narrower than every cluster in the document — over 710 runs of the Tai Tham block only 7 draw differently at0xFFthan at0— but those 7 include the pre-base matra reordering1A20 1A55→1A55 1A20, which is the visually significant kind.This is #89 and #96 one script over, answered the same way: at the seam where the glyph is made, with the category of the character it replaces.
What moves on a page
Nothing. Two sweeps stand behind that:
rtlPUAstron 2 Arabic fonts, +1 codepoint eachThe Tai Tham snapshot was generated against the code before the fix as well as after, and is byte-identical.
Test fonts
NotoSansDevanagari-ContextualLocl-Subset— 4 glyphs of Noto Sans Devanagari 2.005 (OFL 1.1): the contextualloclof the Santali language system, backtracking an independent vowel to substitute a Santali nuktaNotoSansArabic-MultipleForm-Subset— 8 glyphs of Noto Sans Arabic 2.012 (OFL 1.1): the Farsi Yeh, whose initial and medial forms replace it with the dotless form and the pair of dots under it, and a Beh to join it toBoth golden masters cover them from here. The parser fixture holds
rtlPUAstr; the dump fixture holds every diagnostic raised reading the font, so either read coming back is a diff rather than a warning nobody sees. A test beside them asserts each font loads clean, since a deprecation is not converted to an exception and would otherwise pass unnoticed.Not in this PR
The Gurmukhi diagnostic reported in a comment on #104 is #102, and is fixed separately.
🤖 Generated with Claude Code