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

Fix loading SVG table with 0 entries#535
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

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84%. Comparing base (23ce95c) to head (190d1eb).

Additional details and impacted files
@@          Coverage Diff          @@
##            main    #535   +/-   ##
=====================================
  Coverage     84%     84%           
=====================================
  Files        332     332           
  Lines      24666   24668    +2     
  Branches    3610    3611    +1     
=====================================
+ Hits       20769   20771    +2     
  Misses      3010    3010           
  Partials     887     887           
Flag Coverage Δ
unittests 84% <100%> (+<1%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@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