diff --git a/src/UglyToad.PdfPig.Fonts/TrueType/Tables/GlyphDataTable.cs b/src/UglyToad.PdfPig.Fonts/TrueType/Tables/GlyphDataTable.cs index 377034d0..77bb0542 100644 --- a/src/UglyToad.PdfPig.Fonts/TrueType/Tables/GlyphDataTable.cs +++ b/src/UglyToad.PdfPig.Fonts/TrueType/Tables/GlyphDataTable.cs @@ -121,14 +121,23 @@ 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 c2f34168..a06e6e15 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 @@ namespace UglyToad.PdfPig.Tests.Fonts.TrueType.Parser 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 00000000..6e56486e 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 48b5e10f..a4f32175 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 -