Skip to content

Fix loading SVG table with 0 entries#535

Open
natehitze wants to merge 2 commits into
SixLabors:mainfrom
natehitze:fix-issue-534
Open

Fix loading SVG table with 0 entries#535
natehitze wants to merge 2 commits into
SixLabors:mainfrom
natehitze:fix-issue-534

Conversation

@natehitze
Copy link
Copy Markdown

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following matches the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

Fixes #534.

This changes SvgTable.Load(BigEndianBinaryReader) to return null when the SVG table has 0 entries. Its only caller is SvgTable.Load(FontReader), which can already return null if 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.ReadBytes was called with a -9 count:
image

In the caller SvgTable.Load the numEntries value was read as 0.
image

This leaves minRelOffset and maxEnd at their initial values since the i < numEntries loop has nothing to do. The addition to calculate tableStart wraps ((uint) 10 + uint.MaxValue = 9). Then the integer subtraction calculates a negative byteCount ((int)(0 - 9) = -9).

image

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OverflowException when loading font collection

1 participant