diff --git a/src/SixLabors.Fonts/Tables/General/Svg/SvgTable.cs b/src/SixLabors.Fonts/Tables/General/Svg/SvgTable.cs
index 19355bd1d..e2154ac72 100644
--- a/src/SixLabors.Fonts/Tables/General/Svg/SvgTable.cs
+++ b/src/SixLabors.Fonts/Tables/General/Svg/SvgTable.cs
@@ -74,8 +74,8 @@ private SvgTable(byte[] tableData, uint svgDocIndexOffset, uint tableBaseOffset,
/// Loads the SVG table from the specified binary reader.
///
/// The binary reader positioned at the start of the SVG table.
- /// The .
- public static SvgTable Load(BigEndianBinaryReader reader)
+ /// The , or if the table is not valid in the font.
+ public static SvgTable? Load(BigEndianBinaryReader reader)
{
// HEADER
// | Type | Name | Description |
@@ -99,6 +99,12 @@ public static SvgTable Load(BigEndianBinaryReader reader)
// | Entry[numEntries] | entries | Array of SVG Document Index Entries(sorted by startGlyphID).|
reader.Seek(svgDocIndexOffset, SeekOrigin.Begin);
ushort numEntries = reader.ReadUInt16();
+ if (numEntries == 0)
+ {
+ // The spec says the number of entries must be non-zero.
+ return null;
+ }
+
SvgDocumentIndexEntry[] entries = new SvgDocumentIndexEntry[numEntries];
// SVG Document Index Entry
diff --git a/tests/Fonts/Issues/Issue534.ttf b/tests/Fonts/Issues/Issue534.ttf
new file mode 100644
index 000000000..1e082537e
--- /dev/null
+++ b/tests/Fonts/Issues/Issue534.ttf
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:e73d67f92457bd05d24c42f43156bc422e98982e9e62d267ad6d1a3cc595bb01
+size 93580
diff --git a/tests/SixLabors.Fonts.Tests/Issues/Issues_534.cs b/tests/SixLabors.Fonts.Tests/Issues/Issues_534.cs
new file mode 100644
index 000000000..d2c9ca0c7
--- /dev/null
+++ b/tests/SixLabors.Fonts.Tests/Issues/Issues_534.cs
@@ -0,0 +1,17 @@
+// Copyright (c) Six Labors.
+// Licensed under the Six Labors Split License.
+
+namespace SixLabors.Fonts.Tests.Issues;
+
+public class Issues_534
+{
+ [Fact]
+ public void ShouldLoadFontWithSvgTableHavingZeroEntries()
+ {
+ Font font = TestFonts.GetFont(TestFonts.Issues.Issue534, 12);
+
+ FontRectangle size = TextMeasurer.MeasureBounds("ABCabc123", new TextOptions(font));
+
+ Assert.NotEqual(FontRectangle.Empty, size);
+ }
+}
diff --git a/tests/SixLabors.Fonts.Tests/TestFonts.cs b/tests/SixLabors.Fonts.Tests/TestFonts.cs
index fb4991883..4faee25c8 100644
--- a/tests/SixLabors.Fonts.Tests/TestFonts.cs
+++ b/tests/SixLabors.Fonts.Tests/TestFonts.cs
@@ -414,6 +414,8 @@ public static class Issues
public static string Issue512 => GetFullPath("Issues/Issue512.otf");
public static string Issue514 => GetFullPath("Issues/Issue514.ttf");
+
+ public static string Issue534 => GetFullPath("Issues/Issue534.ttf");
}
///