Skip to content

Commit b49e5aa

Browse files
committed
Check for index out of range in GlyphDataTable.ReadFlags() and fix #1199
1 parent 181fa9d commit b49e5aa

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/UglyToad.PdfPig.Fonts/TrueType/Tables/GlyphDataTable.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,15 @@ private static SimpleGlyphFlags[] ReadFlags(TrueTypeDataBytes data, int pointCou
338338

339339
for (int j = 0; j < numberOfRepeats; j++)
340340
{
341-
result[i + j + 1] = result[i];
341+
int p = i + j + 1;
342+
if (p >= result.Length)
343+
{
344+
// Unsure why this happens but fixes #1199
345+
// TODO - Is there a better fix?
346+
break;
347+
}
348+
349+
result[p] = result[i];
342350
}
343351

344352
i += numberOfRepeats;
Binary file not shown.

src/UglyToad.PdfPig.Tests/Integration/GithubIssuesTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@
88

99
public class GithubIssuesTests
1010
{
11+
[Fact]
12+
public void Issue1199()
13+
{
14+
var path = IntegrationHelpers.GetDocumentPath("TrueTypeTablesGlyphDataTableReadGlyphsError.pdf");
15+
16+
using (var document = PdfDocument.Open(path, new ParsingOptions() { UseLenientParsing = true }))
17+
{
18+
for (int p = 1; p <= document.NumberOfPages; p++)
19+
{
20+
var page = document.GetPage(p);
21+
Assert.NotNull(page);
22+
}
23+
}
24+
}
25+
1126
[Fact]
1227
public void Issue1183()
1328
{

0 commit comments

Comments
 (0)