handle case where offsets are out of range
Some checks failed
Build, test and publish draft / build (push) Has been cancelled
Build and test [MacOS] / build (push) Has been cancelled
Run Common Crawl Tests / build (0000-0001) (push) Has been cancelled
Run Common Crawl Tests / build (0002-0003) (push) Has been cancelled
Run Common Crawl Tests / build (0004-0005) (push) Has been cancelled
Run Common Crawl Tests / build (0006-0007) (push) Has been cancelled
Run Integration Tests / build (push) Has been cancelled

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:
EliotJones
2025-09-14 16:00:10 +02:00
committed by BobLd
parent eb906a776d
commit efdedb9495
4 changed files with 27 additions and 20 deletions

View File

@@ -121,14 +121,23 @@
for (var i = 0; i < glyphCount; i++) for (var i = 0; i < glyphCount; i++)
{ {
if (offsets[i + 1] <= offsets[i]) var offset = offsets[i];
if (offsets[i + 1] <= offset)
{ {
// empty glyph // empty glyph
result[i] = emptyGlyph; result[i] = emptyGlyph;
continue; 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(); var contourCount = data.ReadSignedShort();

View File

@@ -229,5 +229,19 @@ namespace UglyToad.PdfPig.Tests.Fonts.TrueType.Parser
Assert.NotNull(font.TableRegister.NameTable); Assert.NotNull(font.TableRegister.NameTable);
Assert.NotEmpty(font.TableRegister.NameTable.NameRecords); 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 _);
}
} }
} }

View File

@@ -39,11 +39,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Remove="Fonts\TrueType\Andada-Regular.ttf" /> <EmbeddedResource Remove="Fonts\TrueType\*.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\Type1\AdobeUtopia.pfa" /> <EmbeddedResource Remove="Fonts\Type1\AdobeUtopia.pfa" />
<EmbeddedResource Remove="Fonts\Type1\CMBX10.pfa" /> <EmbeddedResource Remove="Fonts\Type1\CMBX10.pfa" />
<EmbeddedResource Remove="Fonts\Type1\CMBX12.pfa" /> <EmbeddedResource Remove="Fonts\Type1\CMBX12.pfa" />
@@ -61,24 +57,12 @@
<Content Include="Fonts\CompactFontFormat\MinionPro.bin"> <Content Include="Fonts\CompactFontFormat\MinionPro.bin">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Fonts\TrueType\Andada-Regular.ttf"> <Content Include="Fonts\TrueType\*.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">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Fonts\TrueType\Roboto-Regular.GlyphData.txt"> <Content Include="Fonts\TrueType\Roboto-Regular.GlyphData.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="Fonts\TrueType\Roboto-Regular.ttf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Fonts\Type1\AdobeUtopia.pfa" /> <Content Include="Fonts\Type1\AdobeUtopia.pfa" />
<Content Include="Fonts\Type1\CMBX10.pfa" /> <Content Include="Fonts\Type1\CMBX10.pfa" />
<Content Include="Fonts\Type1\CMBX12.pfa" /> <Content Include="Fonts\Type1\CMBX12.pfa" />