Image data might contain trailing EOL marker

This commit is contained in:
Kasper Frank
2021-05-10 17:27:08 +02:00
parent 07823c8b34
commit 6fa223c0db

View File

@@ -2,6 +2,8 @@
{
using Content;
using Graphics.Colors;
using System.Collections.Generic;
using UglyToad.PdfPig.Core;
internal static class PngFromPdfImageFactory
{
@@ -32,7 +34,18 @@
var builder = PngBuilder.Create(image.WidthInSamples, image.HeightInSamples, false);
var isCorrectlySized = bytesPure.Count == (image.WidthInSamples * image.HeightInSamples * numberOfComponents);
var requiredSize = (image.WidthInSamples * image.HeightInSamples * numberOfComponents);
var actualSize = bytesPure.Count;
var isCorrectlySized = bytesPure.Count == requiredSize ||
// Spec, p. 37: "...error if the stream contains too much data, with the exception that
// there may be an extra end-of-line marker..."
(actualSize == requiredSize + 1 && bytesPure[actualSize - 1] == ReadHelper.AsciiLineFeed) ||
(actualSize == requiredSize + 1 && bytesPure[actualSize - 1] == ReadHelper.AsciiCarriageReturn) ||
// The combination of a CARRIAGE RETURN followed immediately by a LINE FEED is treated as one EOL marker.
(actualSize == requiredSize + 2 &&
bytesPure[actualSize - 2] == ReadHelper.AsciiCarriageReturn &&
bytesPure[actualSize - 1] == ReadHelper.AsciiLineFeed);
if (!isCorrectlySized)
{