mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-09-18 18:27:55 +08:00
handle case where offsets are out of range
Some checks are pending
Build, test and publish draft / build (push) Waiting to run
Build and test [MacOS] / build (push) Waiting to run
Run Common Crawl Tests / build (0000-0001) (push) Waiting to run
Run Common Crawl Tests / build (0002-0003) (push) Waiting to run
Run Common Crawl Tests / build (0004-0005) (push) Waiting to run
Run Common Crawl Tests / build (0006-0007) (push) Waiting to run
Run Integration Tests / build (push) Waiting to run
Some checks are pending
Build, test and publish draft / build (push) Waiting to run
Build and test [MacOS] / build (push) Waiting to run
Run Common Crawl Tests / build (0000-0001) (push) Waiting to run
Run Common Crawl Tests / build (0002-0003) (push) Waiting to run
Run Common Crawl Tests / build (0004-0005) (push) Waiting to run
Run Common Crawl Tests / build (0006-0007) (push) Waiting to run
Run Integration Tests / build (push) Waiting to run
default to returning empty glyph where the offset is out of the file length range, this fixes file 12623 where the truetype file is completely broken
This commit is contained in:
@@ -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();
|
||||
|
||||
|
@@ -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 _);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
BIN
src/UglyToad.PdfPig.Tests/Fonts/TrueType/corrupt-12623.ttf
Normal file
BIN
src/UglyToad.PdfPig.Tests/Fonts/TrueType/corrupt-12623.ttf
Normal file
Binary file not shown.
@@ -39,11 +39,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Remove="Fonts\TrueType\Andada-Regular.ttf" />
|
||||
<EmbeddedResource Remove="Fonts\TrueType\google-simple-doc.ttf" />
|
||||
<EmbeddedResource Remove="Fonts\TrueType\issue-258-corrupt-name-table.ttf" />
|
||||
<EmbeddedResource Remove="Fonts\TrueType\PMingLiU.ttf" />
|
||||
<EmbeddedResource Remove="Fonts\TrueType\Roboto-Regular.ttf" />
|
||||
<EmbeddedResource Remove="Fonts\TrueType\*.ttf" />
|
||||
<EmbeddedResource Remove="Fonts\Type1\AdobeUtopia.pfa" />
|
||||
<EmbeddedResource Remove="Fonts\Type1\CMBX10.pfa" />
|
||||
<EmbeddedResource Remove="Fonts\Type1\CMBX12.pfa" />
|
||||
@@ -61,24 +57,12 @@
|
||||
<Content Include="Fonts\CompactFontFormat\MinionPro.bin">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Fonts\TrueType\Andada-Regular.ttf">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Fonts\TrueType\google-simple-doc.ttf">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Fonts\TrueType\issue-258-corrupt-name-table.ttf">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Fonts\TrueType\PMingLiU.ttf">
|
||||
<Content Include="Fonts\TrueType\*.ttf">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Fonts\TrueType\Roboto-Regular.GlyphData.txt">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Fonts\TrueType\Roboto-Regular.ttf">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Fonts\Type1\AdobeUtopia.pfa" />
|
||||
<Content Include="Fonts\Type1\CMBX10.pfa" />
|
||||
<Content Include="Fonts\Type1\CMBX12.pfa" />
|
||||
|
Reference in New Issue
Block a user