Browse Source

Throw exception, if palette chunk is missing

pull/2020/head
Brian Popow 4 years ago
parent
commit
892dbe318f
  1. 5
      src/ImageSharp/Formats/Png/PngScanlineProcessor.cs
  2. 3
      src/ImageSharp/Formats/Png/PngThrowHelper.cs

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 palette chunk");
[MethodImpl(InliningOptions.ColdPath)]
public static void ThrowInvalidChunkType() => throw new InvalidImageContentException("Invalid PNG data.");

Loading…
Cancel
Save