Browse Source

Merge pull request #2985 from mus65/backport_2926_2.1

Backport #2926 to release/2.1.x
release/2.1.x v2.1.12
James Jackson-South 4 months ago
committed by GitHub
parent
commit
168f3f550b
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 21
      src/ImageSharp/Formats/Png/PngDecoderCore.cs
  2. 10
      tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
  3. 3
      tests/ImageSharp.Tests/TestImages.cs
  4. 3
      tests/Images/External/ReferenceOutput/PngDecoderTests/CanDecode_Issue2924_Rgba32_Issue_2924.png
  5. 3
      tests/Images/Input/Png/issues/Issue_2924.png

21
src/ImageSharp/Formats/Png/PngDecoderCore.cs

@ -114,6 +114,11 @@ namespace SixLabors.ImageSharp.Formats.Png
/// </summary>
private PngChunk? nextChunk;
/// <summary>
/// A value indicating whether the image data has been read.
/// </summary>
private bool hasImageData;
/// <summary>
/// Initializes a new instance of the <see cref="PngDecoderCore"/> class.
/// </summary>
@ -565,7 +570,11 @@ namespace SixLabors.ImageSharp.Formats.Png
where TPixel : unmanaged, IPixel<TPixel>
{
using var deframeStream = new ZlibInflateStream(this.currentStream, this.ReadNextDataChunk);
deframeStream.AllocateNewBytes(chunk.Length, true);
if (!deframeStream.AllocateNewBytes(chunk.Length, !this.hasImageData))
{
return;
}
DeflateStream dataStream = deframeStream.CompressedStream;
if (this.header.InterlaceMethod == PngInterlaceMode.Adam7)
@ -596,7 +605,7 @@ namespace SixLabors.ImageSharp.Formats.Png
int bytesRead = compressedStream.Read(scanlineSpan, this.currentRowBytesRead, this.bytesPerScanline - this.currentRowBytesRead);
if (bytesRead <= 0)
{
return;
goto EXIT;
}
this.currentRowBytesRead += bytesRead;
@ -635,6 +644,9 @@ namespace SixLabors.ImageSharp.Formats.Png
this.SwapScanlineBuffers();
this.currentRow++;
}
EXIT:
this.hasImageData = true;
}
/// <summary>
@ -672,7 +684,7 @@ namespace SixLabors.ImageSharp.Formats.Png
int bytesRead = compressedStream.Read(this.scanline.GetSpan(), this.currentRowBytesRead, bytesPerInterlaceScanline - this.currentRowBytesRead);
if (bytesRead <= 0)
{
return;
goto EXIT;
}
this.currentRowBytesRead += bytesRead;
@ -729,6 +741,9 @@ namespace SixLabors.ImageSharp.Formats.Png
pass = 0;
break;
}
EXIT:
this.hasImageData = true;
}
}

10
tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs

@ -534,5 +534,15 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
string path = Path.GetFullPath(Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, file));
using Image image = Image.Load(path);
}
[Theory]
[WithFile(TestImages.Png.Issue2924, PixelTypes.Rgba32)]
public void CanDecode_Issue2924<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(PngDecoder);
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
}
}
}

3
tests/ImageSharp.Tests/TestImages.cs

@ -125,6 +125,9 @@ namespace SixLabors.ImageSharp.Tests
// Discussion 1875: https://github.com/SixLabors/ImageSharp/discussions/1875
public const string Issue1875 = "Png/raw-profile-type-exif.png";
// Issue 2924: https://github.com/SixLabors/ImageSharp/issues/2924
public const string Issue2924 = "Png/issues/Issue_2924.png";
public static class Bad
{
public const string MissingDataChunk = "Png/xdtn0g01.png";

3
tests/Images/External/ReferenceOutput/PngDecoderTests/CanDecode_Issue2924_Rgba32_Issue_2924.png

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:4347cd89196c09496288724afdd876b227063149bba33615c338ebb474a0cb19
size 47260

3
tests/Images/Input/Png/issues/Issue_2924.png

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:fd366a2de522041c706729b01a6030df6c82a4e87ea3509cc78a47486f097044
size 49376
Loading…
Cancel
Save