Browse Source

Merge branch 'main' into js/fix-2012

pull/2014/head
James Jackson-South 4 years ago
committed by GitHub
parent
commit
eda0906796
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      src/ImageSharp/Formats/Png/PngScanlineProcessor.cs
  2. 3
      src/ImageSharp/Formats/Png/PngThrowHelper.cs
  3. 16
      tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
  4. 2
      tests/ImageSharp.Tests/TestImages.cs
  5. 3
      tests/Images/Input/Png/missing_plte.png
  6. 3
      tests/Images/Input/Png/missing_plte_2.png

5
src/ImageSharp/Formats/Png/PngScanlineProcessor.cs

@ -240,6 +240,11 @@ namespace SixLabors.ImageSharp.Formats.Png
byte[] paletteAlpha)
where TPixel : unmanaged, IPixel<TPixel>
{
if (palette.IsEmpty)
{
PngThrowHelper.ThrowMissingPalette();
}
TPixel pixel = default;
ref byte scanlineSpanRef = ref MemoryMarshal.GetReference(scanlineSpan);
ref TPixel rowSpanRef = ref MemoryMarshal.GetReference(rowSpan);

3
src/ImageSharp/Formats/Png/PngThrowHelper.cs

@ -21,6 +21,9 @@ namespace SixLabors.ImageSharp.Formats.Png
[MethodImpl(InliningOptions.ColdPath)]
public static void ThrowNoData() => throw new InvalidImageContentException("PNG Image does not contain a data chunk");
[MethodImpl(InliningOptions.ColdPath)]
public static void ThrowMissingPalette() => throw new InvalidImageContentException("PNG Image does not contain a palette chunk");
[MethodImpl(InliningOptions.ColdPath)]
public static void ThrowInvalidChunkType() => throw new InvalidImageContentException("Invalid PNG data.");

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

@ -265,6 +265,22 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
Assert.Contains("PNG Image does not contain a data chunk", ex.Message);
}
[Theory]
[WithFile(TestImages.Png.Bad.MissingPaletteChunk1, PixelTypes.Rgba32)]
[WithFile(TestImages.Png.Bad.MissingPaletteChunk2, PixelTypes.Rgba32)]
public void Decode_MissingPaletteChunk_ThrowsException<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
Exception ex = Record.Exception(
() =>
{
using Image<TPixel> image = provider.GetImage(PngDecoder);
image.DebugSave(provider);
});
Assert.NotNull(ex);
Assert.Contains("PNG Image does not contain a palette chunk", ex.Message);
}
[Theory]
[WithFile(TestImages.Png.Bad.BitDepthZero, PixelTypes.Rgba32)]
[WithFile(TestImages.Png.Bad.BitDepthThree, PixelTypes.Rgba32)]

2
tests/ImageSharp.Tests/TestImages.cs

@ -127,6 +127,8 @@ namespace SixLabors.ImageSharp.Tests
public const string MissingDataChunk = "Png/xdtn0g01.png";
public const string WrongCrcDataChunk = "Png/xcsn0g01.png";
public const string CorruptedChunk = "Png/big-corrupted-chunk.png";
public const string MissingPaletteChunk1 = "Png/missing_plte.png";
public const string MissingPaletteChunk2 = "Png/missing_plte_2.png";
// Zlib errors.
public const string ZlibOverflow = "Png/zlib-overflow.png";

3
tests/Images/Input/Png/missing_plte.png

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:73fd17a394f8258f4767986bc427c0160277819349c937f18cb29044e7549bc8
size 506

3
tests/Images/Input/Png/missing_plte_2.png

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