diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index bca682d77a..0a7a5d359b 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -1253,6 +1253,12 @@ internal sealed class PngDecoderCore : ImageDecoderCore ReadOnlySpan rgbTable = MemoryMarshal.Cast(palette); Color.FromPixel(rgbTable, colorTable); + if (alpha.Length > colorTable.Length) + { + throw new InvalidImageContentException( + "The tRNS chunk contains more alpha values than there are palette entries."); + } + if (alpha.Length > 0) { // The alpha chunk may contain as many transparency entries as there are palette entries