From 21c5f26869aa77a9a0fc3107f5e30fe3d739fd95 Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Mon, 3 Mar 2025 18:51:06 +0100 Subject: [PATCH] Handle images with invalid resolution --- openVulkanoCpp/IO/Files/Pfm.hpp | 8 ++++++++ openVulkanoCpp/IO/Files/Pnm.hpp | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/openVulkanoCpp/IO/Files/Pfm.hpp b/openVulkanoCpp/IO/Files/Pfm.hpp index 55b1bed..ed3967b 100644 --- a/openVulkanoCpp/IO/Files/Pfm.hpp +++ b/openVulkanoCpp/IO/Files/Pfm.hpp @@ -94,6 +94,14 @@ namespace OpenVulkano void Read(std::istream& inStream) { inStream >> header; + + if (header.width == UINT32_MAX || header.height == UINT32_MAX) + { + header.width = header.height = 0; + image = nullptr; + return; + } + size_t size = header.GetElementCount(); image = std::make_unique(size); diff --git a/openVulkanoCpp/IO/Files/Pnm.hpp b/openVulkanoCpp/IO/Files/Pnm.hpp index f0995b4..95ee297 100644 --- a/openVulkanoCpp/IO/Files/Pnm.hpp +++ b/openVulkanoCpp/IO/Files/Pnm.hpp @@ -139,6 +139,13 @@ namespace OpenVulkano // TODO handle ascii mode if (header.ascii) throw std::runtime_error("ascii mode not supported!"); + if (header.width == UINT32_MAX || header.height == UINT32_MAX) + { + header.width = header.height = 0; + image = nullptr; + return; + } + size_t size = header.GetImageSize(); image = std::make_unique(size); inStream.read(image.get(), size);