Fix loading SVG table with 0 entries by natehitze · Pull Request #535 · SixLabors/Fonts · GitHub
Skip to content

Fix loading SVG table with 0 entries - #535

Merged
JimBobSquarePants merged 2 commits into
SixLabors:mainfrom
natehitze:fix-issue-534
May 25, 2026
Merged

JimBobSquarePants merged 2 commits into
SixLabors:mainfrom
natehitze:fix-issue-534

Conversation

@natehitze

Copy link
Copy Markdown
Contributor

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.

@codecov

codecov Bot commented May 25, 2026

Copy link
Copy Markdown

@JimBobSquarePants JimBobSquarePants left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fantastic. Thank you so much!

@JimBobSquarePants
JimBobSquarePants merged commit 5a01a59 into SixLabors:main May 25, 2026
10 checks passed
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

2 participants