Skip to content

Commit fdb8835

Browse files
committed
CcittFaxDecodeFilter: do not check for input length, invert bitmap with ref byte and fix #982
1 parent 5209850 commit fdb8835

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,24 @@
77

88
public class GithubIssuesTests
99
{
10+
[Fact]
11+
public void Issue982()
12+
{
13+
var path = IntegrationHelpers.GetSpecificTestDocumentPath("PDFBOX-659-0.pdf");
14+
15+
using (var document = PdfDocument.Open(path))
16+
{
17+
for (int p = 1; p <= document.NumberOfPages; ++p)
18+
{
19+
var page = document.GetPage(p);
20+
foreach (var pdfImage in page.GetImages())
21+
{
22+
Assert.True(pdfImage.TryGetPng(out _));
23+
}
24+
}
25+
}
26+
}
27+
1028
[Fact]
1129
public void Issue973()
1230
{
@@ -25,11 +43,11 @@ public void Issue973()
2543
using (var document = PdfDocument.Open(path, new ParsingOptions() { UseLenientParsing = false }))
2644
{
2745
var exception = Assert.Throws<InvalidOperationException>(() => document.GetPage(2));
28-
Assert.Equal("Cannot execute a pop of the graphics state stack, it would leave the stack empty.", exception.Message);
46+
Assert.Equal("Cannot execute a pop of the graphics state stack, it would leave the stack empty.",
47+
exception.Message);
2948
}
3049
}
3150

32-
3351
[Fact]
3452
public void Issue959()
3553
{
Binary file not shown.

src/UglyToad.PdfPig/Filters/CcittFaxDecodeFilter.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using CcittFax;
77
using Util;
88

9+
// Filter updated from original port because of issue #982
10+
911
/// <summary>
1012
/// Decodes image data that has been encoded using either Group 3 or Group 4.
1113
/// <para>
@@ -62,11 +64,6 @@ private static CcittFaxCompressionType DetermineCompressionType(ReadOnlySpan<byt
6264
{
6365
var compressionType = CcittFaxCompressionType.Group3_1D; // Group 3 1D
6466

65-
if (input.Length < 20)
66-
{
67-
throw new InvalidOperationException("The format is invalid");
68-
}
69-
7067
if (input[0] != 0 || (input[1] >> 4 != 1 && input[1] != 1))
7168
{
7269
// leading EOL (0b000000000001) not found, search further and
@@ -114,7 +111,8 @@ private static void InvertBitmap(Span<byte> bufferData)
114111
{
115112
for (int i = 0, c = bufferData.Length; i < c; i++)
116113
{
117-
bufferData[i] = (byte)(~bufferData[i] & 0xFF);
114+
ref byte b = ref bufferData[i];
115+
b = (byte)(~b & 0xFF);
118116
}
119117
}
120118
}

0 commit comments

Comments
 (0)