From ad16b754ae2a13d40f2ff24399863449e38d2293 Mon Sep 17 00:00:00 2001 From: morkt Date: Mon, 17 Jul 2017 11:04:39 +0400 Subject: [PATCH] (PngFormat.ReadMetaData): additional sanity checks. --- GameRes/ImagePNG.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/GameRes/ImagePNG.cs b/GameRes/ImagePNG.cs index 67eaad35..4de63b2d 100644 --- a/GameRes/ImagePNG.cs +++ b/GameRes/ImagePNG.cs @@ -129,6 +129,8 @@ namespace GameRes meta.Width = Binary.BigEndian (file.ReadUInt32()); meta.Height = Binary.BigEndian (file.ReadUInt32()); int bpp = file.ReadByte(); + if (bpp != 1 && bpp != 2 && bpp != 4 && bpp != 8 && bpp != 16) + return null; int color_type = file.ReadByte(); switch (color_type) { @@ -136,7 +138,8 @@ namespace GameRes case 3: meta.BPP = 24; break; case 4: meta.BPP = bpp*2; break; case 6: meta.BPP = bpp*4; break; - default: meta.BPP = bpp; break; + case 0: meta.BPP = bpp; break; + default: return null; } SkipBytes (file, 7);