From 97ba0292d6177a22edd7cf41589af701d5a696cd Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Sat, 25 Jul 2015 17:23:59 +0300 Subject: [PATCH] Fix crash on loading invalid PNG files (Just a divide by zero) --- src/library/png.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/library/png.cpp b/src/library/png.cpp index 7ffcf560..0e7ef616 100644 --- a/src/library/png.cpp +++ b/src/library/png.cpp @@ -816,6 +816,8 @@ void decoder::decode_png(std::istream& stream) std::vector ndata; std::vector npalette; ndata.resize(hdr.width * hdr.height); + if(hdr.width == 0 || hdr.height == 0) + throw std::runtime_error("PNG file has zero width or height"); if(ndata.size() / hdr.width != hdr.height) throw std::bad_alloc(); if(hdr.type == 3) {