CcittFaxDecodeFilter: do not check for input length, invert bitmap with ref byte and fix #982
Some checks failed
Build and test / build (push) Has been cancelled
Run Integration Tests / build (push) Has been cancelled

This commit is contained in:
BobLd 2025-02-02 14:09:22 +00:00
parent 5209850af7
commit fdb8835b37
3 changed files with 24 additions and 8 deletions

View File

@ -7,6 +7,24 @@
public class GithubIssuesTests
{
[Fact]
public void Issue982()
{
var path = IntegrationHelpers.GetSpecificTestDocumentPath("PDFBOX-659-0.pdf");
using (var document = PdfDocument.Open(path))
{
for (int p = 1; p <= document.NumberOfPages; ++p)
{
var page = document.GetPage(p);
foreach (var pdfImage in page.GetImages())
{
Assert.True(pdfImage.TryGetPng(out _));
}
}
}
}
[Fact]
public void Issue973()
{
@ -25,11 +43,11 @@
using (var document = PdfDocument.Open(path, new ParsingOptions() { UseLenientParsing = false }))
{
var exception = Assert.Throws<InvalidOperationException>(() => document.GetPage(2));
Assert.Equal("Cannot execute a pop of the graphics state stack, it would leave the stack empty.", exception.Message);
Assert.Equal("Cannot execute a pop of the graphics state stack, it would leave the stack empty.",
exception.Message);
}
}
[Fact]
public void Issue959()
{

View File

@ -6,6 +6,8 @@
using CcittFax;
using Util;
// Filter updated from original port because of issue #982
/// <summary>
/// Decodes image data that has been encoded using either Group 3 or Group 4.
/// <para>
@ -62,11 +64,6 @@
{
var compressionType = CcittFaxCompressionType.Group3_1D; // Group 3 1D
if (input.Length < 20)
{
throw new InvalidOperationException("The format is invalid");
}
if (input[0] != 0 || (input[1] >> 4 != 1 && input[1] != 1))
{
// leading EOL (0b000000000001) not found, search further and
@ -114,7 +111,8 @@
{
for (int i = 0, c = bufferData.Length; i < c; i++)
{
bufferData[i] = (byte)(~bufferData[i] & 0xFF);
ref byte b = ref bufferData[i];
b = (byte)(~b & 0xFF);
}
}
}