diff --git a/src/UglyToad.PdfPig.Fonts/TrueType/Tables/GlyphDataTable.cs b/src/UglyToad.PdfPig.Fonts/TrueType/Tables/GlyphDataTable.cs index 377034d0b..77bb05423 100644 --- a/src/UglyToad.PdfPig.Fonts/TrueType/Tables/GlyphDataTable.cs +++ b/src/UglyToad.PdfPig.Fonts/TrueType/Tables/GlyphDataTable.cs @@ -121,14 +121,23 @@ private IReadOnlyList ReadGlyphs() for (var i = 0; i < glyphCount; i++) { - if (offsets[i + 1] <= offsets[i]) + var offset = offsets[i]; + + if (offsets[i + 1] <= offset) { // empty glyph result[i] = emptyGlyph; continue; } - data.Seek(offsets[i]); + // Invalid table, just sub in the empty glyph + if (offset >= data.Length) + { + result[i] = emptyGlyph; + continue; + } + + data.Seek(offset); var contourCount = data.ReadSignedShort(); diff --git a/src/UglyToad.PdfPig.Tests/Fonts/TrueType/Parser/TrueTypeFontParserTests.cs b/src/UglyToad.PdfPig.Tests/Fonts/TrueType/Parser/TrueTypeFontParserTests.cs index c2f341688..a06e6e157 100644 --- a/src/UglyToad.PdfPig.Tests/Fonts/TrueType/Parser/TrueTypeFontParserTests.cs +++ b/src/UglyToad.PdfPig.Tests/Fonts/TrueType/Parser/TrueTypeFontParserTests.cs @@ -229,5 +229,19 @@ public void ParseIssue258CorruptNameTable() Assert.NotNull(font.TableRegister.NameTable); Assert.NotEmpty(font.TableRegister.NameTable.NameRecords); } + + [Fact] + public void Parse12623CorruptFileAndGetGlyphs() + { + var bytes = TrueTypeTestHelper.GetFileBytes("corrupt-12623"); + + var input = new TrueTypeDataBytes(new MemoryInputBytes(bytes)); + + var font = TrueTypeFontParser.Parse(input); + + Assert.NotNull(font); + + font.TryGetPath(1, out _); + } } } diff --git a/src/UglyToad.PdfPig.Tests/Fonts/TrueType/corrupt-12623.ttf b/src/UglyToad.PdfPig.Tests/Fonts/TrueType/corrupt-12623.ttf new file mode 100644 index 000000000..6e56486e1 Binary files /dev/null and b/src/UglyToad.PdfPig.Tests/Fonts/TrueType/corrupt-12623.ttf differ diff --git a/src/UglyToad.PdfPig.Tests/UglyToad.PdfPig.Tests.csproj b/src/UglyToad.PdfPig.Tests/UglyToad.PdfPig.Tests.csproj index 48b5e10f0..a4f321759 100644 --- a/src/UglyToad.PdfPig.Tests/UglyToad.PdfPig.Tests.csproj +++ b/src/UglyToad.PdfPig.Tests/UglyToad.PdfPig.Tests.csproj @@ -39,11 +39,7 @@ - - - - - + @@ -61,24 +57,12 @@ PreserveNewest - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - + PreserveNewest PreserveNewest - - PreserveNewest -