From 3e6e897ce82d3647ff9af010e73466712b8e79ad Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 4 Dec 2024 13:59:29 +0300 Subject: [PATCH] fix png signature check --- src/coders/png.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/coders/png.cpp b/src/coders/png.cpp index 60965ed1..b29afd34 100644 --- a/src/coders/png.cpp +++ b/src/coders/png.cpp @@ -13,7 +13,7 @@ static debug::Logger logger("png-coder"); // returns 0 if all-right, 1 otherwise -int _png_write( +static int png_write( const char* filename, uint width, uint height, const ubyte* data, bool alpha ) { uint pixsize = alpha ? 4 : 3; @@ -112,7 +112,7 @@ static void read_in_memory(png_structp pngPtr, png_bytep dst, png_size_t toread) } std::unique_ptr png::load_image(const ubyte* bytes, size_t size) { - if (!png_check_sig(bytes, size)) { + if (size < 8 || !png_check_sig(bytes, 8)) { throw std::runtime_error("invalid png signature"); } png_structp pngPtr = nullptr; @@ -223,7 +223,7 @@ std::unique_ptr png::load_texture(const std::string& filename) { } void png::write_image(const std::string& filename, const ImageData* image) { - _png_write( + png_write( filename.c_str(), image->getWidth(), image->getHeight(),