From 0dc1929379f3cc628be7d6b50297c203b87f7a4d Mon Sep 17 00:00:00 2001 From: ftrvxmtrx Date: Sun, 14 Dec 2014 22:20:06 +0100 Subject: png: fail on invalid bpc --- sys/src/cmd/jpg/readpng.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sys/src/cmd/jpg/readpng.c b/sys/src/cmd/jpg/readpng.c index ef14e013f..a046b0cfa 100644 --- a/sys/src/cmd/jpg/readpng.c +++ b/sys/src/cmd/jpg/readpng.c @@ -420,30 +420,40 @@ readslave(Biobuf *b) nout = 0; switch(colorfmt){ case 0: /* grey */ + if(bpc != 1 && bpc != 2 && bpc != 4 && bpc != 8 && bpc != 16) + sysfatal("invalid greyscale bpc %d", bpc); image->nchans = 1; image->chandesc = CY; nout = 1; nchan = 1; break; case 2: /* rgb */ + if(bpc != 8 && bpc != 16) + sysfatal("invalid rgb bpc %d", bpc); image->nchans = 1; image->chandesc = CRGB24; nout = 3; nchan = 3; break; case 3: /* indexed rgb with PLTE */ + if(bpc != 1 && bpc != 2 && bpc != 4 && bpc != 8) + sysfatal("invalid indexed rgb bpc %d", bpc); image->nchans = 1; image->chandesc = CRGB24; nout = 3; nchan = 1; break; case 4: /* grey+alpha */ + if(bpc != 8 && bpc != 16) + sysfatal("invalid grey+alpha bpc %d", bpc); image->nchans = 1; image->chandesc = CYA16; nout = 2; nchan = 2; break; case 6: /* rgb+alpha */ + if(bpc != 8 && bpc != 16) + sysfatal("invalid rgb+alpha bpc %d", bpc); image->nchans = 1; image->chandesc = CRGBA32; nout = 4; -- cgit v1.2.3