Fix loading SVG table with 0 entries#535
Open
natehitze wants to merge 2 commits into
Open
Conversation
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.
Prerequisites
Description
Fixes #534.
This changes
SvgTable.Load(BigEndianBinaryReader)to returnnullwhen the SVG table has 0 entries. Its only caller isSvgTable.Load(FontReader), which can already returnnullif the table isn't found.Added font is licensed CC0: https://ggbot.itch.io/home-video-font
Thought Process
I have no experience with fonts but it seemed like a straightforward change.
When running the debugger, I saw

BigEndianBinaryReader.ReadByteswas called with a-9count:In the caller

SvgTable.LoadthenumEntriesvalue was read as0.This leaves
minRelOffsetandmaxEndat their initial values since thei < numEntriesloop has nothing to do. The addition to calculatetableStartwraps ((uint) 10 + uint.MaxValue = 9). Then the integer subtraction calculates a negativebyteCount((int)(0 - 9) = -9).The easiest approach was to treat an empty table as the table being missing, even though having no entries doesn't appear to be allowed in the spec. This specific font was working in the previous Fonts version and other programs are able to load and render it, so I think it isn't so invalid that it can't work.