From 770409140fa81122a90c7fc735ea760325e6d8e9 Mon Sep 17 00:00:00 2001 From: OLEGSHA Date: Tue, 28 Mar 2023 22:31:15 +0200 Subject: [PATCH] TMP / Fixed image.cpp --- main/rendering/image.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/main/rendering/image.cpp b/main/rendering/image.cpp index 4f20269..5ddaf88 100644 --- a/main/rendering/image.cpp +++ b/main/rendering/image.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include "stb/stb_image.h" @@ -23,7 +24,7 @@ Image::Byte *Image::getData() { return data.data(); } Image loadImage(const std::string &path) { - auto resource = __embedded_resources::getEmbeddedResource(path.c_str()); + auto resource = __embedded_resources::getEmbeddedResource(path); if (resource.data == nullptr) { // REPORT_ERROR @@ -35,15 +36,22 @@ Image loadImage(const std::string &path) { std::vector png(resource.data, resource.data + resource.length); - int width; - int height; - int channelsInFile; + if (png.size() > std::numeric_limits::max()) { + // REPORT_ERROR + progressia::main::logging::fatal() + << "Could not load \"" << path << "\": image file too large"; + exit(1); + } - Image::Byte *stbAllocatedData = - stbi_load_from_memory(png.data(), png.size(), &width, &height, - &channelsInFile, STBI_rgb_alpha); + int dataSize = static_cast(png.size()); + int width = 0; + int height = 0; + int channelsInFile = 0; - if (stbAllocatedData == NULL) { + Image::Byte *stbAllocatedData = stbi_load_from_memory( + png.data(), dataSize, &width, &height, &channelsInFile, STBI_rgb_alpha); + + if (stbAllocatedData == nullptr) { fatal() << "Could not decode a PNG image from file " << path; // REPORT_ERROR exit(1);