Skip to content

Commit 6ad24af

Browse files
Use safe iteration for reading color palette.
1 parent 78fd1b9 commit 6ad24af

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/ImageSharp/Formats/Png/PngDecoderCore.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -933,10 +933,10 @@ private static void AssignColorPalette(ReadOnlySpan<byte> palette, ReadOnlySpan<
933933
}
934934

935935
Color[] colorTable = new Color[palette.Length / Unsafe.SizeOf<Rgb24>()];
936-
ref Rgb24 paletteBase = ref MemoryMarshal.GetReference(MemoryMarshal.Cast<byte, Rgb24>(palette));
936+
ReadOnlySpan<Rgb24> rgbTable = MemoryMarshal.Cast<byte, Rgb24>(palette);
937937
for (int i = 0; i < colorTable.Length; i++)
938938
{
939-
colorTable[i] = new Color(Unsafe.Add(ref paletteBase, (uint)i));
939+
colorTable[i] = new Color(rgbTable[i]);
940940
}
941941

942942
if (alpha.Length > 0)

0 commit comments

Comments
 (0)