Repository navigation
Draw a font the document does not hold in a registered fallback font - #132
Merged
Merged
Conversation
A registered fallback font is loaded from its own file, not through the font mapper, so it has no substitution record. CPDF_Font::ShouldApplyGlyphSpacingHeuristic() read that record from every font that stands in for one the document names, and crashed: a read of null in native builds, "memory access out of bounds" in WebAssembly. Take a font without a record as standing in for the named one, so its glyphs are fitted to the widths the document gives.
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.
Cause
When PDFium's substitute for a font has no glyph for a character,
CPDF_Font::FallbackFontFromCharcodepicks the font that draws it. Upstream that is alwaysLoadSubstFace("Arial"), which comes with aCFX_SubstFont. Ours takes a registered fallback font first, and those are loaded from their own file, not through the font mapper, so they have noCFX_SubstFont.CPDF_Font::ShouldApplyGlyphSpacingHeuristicreads the record without a check, so a render that reaches it with a registered font crashes: a read of address0x1ain native builds,memory access out of boundsin WebAssembly.It takes a font that the document names but does not embed, that is not one of the 14 standard fonts, has widths, is written horizontally, and has a character that the substitute lacks and a registered fallback font has. The test of 18d23c9 did not reach it: its font is named Helvetica and has no widths, and either returns before the read.
Change
fontsrule says what a registered fallback font does for the page's own text, names the guard, and says that a font fromGetFontFallback()may have noCFX_SubstFont. This was the only place that read it unchecked.Tests
EPDFAnnotEmbedderTest.RegisteredFallbackFontRendersUnembeddedFont: a character in a font the document does not hold, as a Type0 font and as a simple TrueType font, with the widths 1000 and 500. It is drawn, and stays inside its width. It runs without system fonts, as WebAssembly does (ScopedNoSystemFonts).Checked
cpdf_font.cpp:261, address0x1a, the crash of the released library. With the heuristic off for such a font instead (return false), it fails on the widths, 67 pixels where 36 fit.EPDFSlicedLoadEmbedderTest.SlicesKeepToTheirBudget, a time budget on a busy machine (run in turns with the base build, both passed 0 of 15).check-fork-tags.py --strict,check-c-api.py(604 functions),check-globals.pyon the macOS library.Left