mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-11-28 09:28:25 +08:00
Image data might contain trailing EOL marker
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user