Skip to content

Commit d355fc0

Browse files
committed
Throw Exception when alpha.Length > colorTable.Length in tRNS chunk
1 parent 89face0 commit d355fc0

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/ImageSharp/Formats/Png/PngDecoderCore.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,12 @@ private static void AssignColorPalette(ReadOnlySpan<byte> palette, ReadOnlySpan<
12531253
ReadOnlySpan<Rgb24> rgbTable = MemoryMarshal.Cast<byte, Rgb24>(palette);
12541254
Color.FromPixel(rgbTable, colorTable);
12551255

1256+
if (alpha.Length > colorTable.Length)
1257+
{
1258+
throw new InvalidImageContentException(
1259+
"The tRNS chunk contains more alpha values than there are palette entries.");
1260+
}
1261+
12561262
if (alpha.Length > 0)
12571263
{
12581264
// The alpha chunk may contain as many transparency entries as there are palette entries

0 commit comments

Comments
 (0)