From fb1365c76c76a149f0cbd233af82c562819bd429 Mon Sep 17 00:00:00 2001 From: dehua Date: Fri, 12 Jul 2024 18:38:09 +0800 Subject: [PATCH] Fix resolution parsing issue in HDR image header reading - Added safety checks for string to integer conversion. --- include/imageinfo.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/imageinfo.hpp b/include/imageinfo.hpp index 9b26df8..1cfa48c 100644 --- a/include/imageinfo.hpp +++ b/include/imageinfo.hpp @@ -642,7 +642,9 @@ inline bool try_gif(ReadInterface &ri, size_t length, ImageInfo &info) { ); return true; } - +inline bool is_numeric(const std::string& str) { + return !str.empty() && std::all_of(str.begin(), str.end(), ::isdigit); +} //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // http://paulbourke.net/dataformats/pic/ @@ -701,6 +703,8 @@ inline bool try_hdr(ReadInterface &ri, size_t length, ImageInfo &info) { } auto y_str = resolution.substr(p0 + 1, p1 - p0 - 1); auto x_str = resolution.substr(p2 + 1); + if( !is_numeric(x_str) || !is_numeric(y_str)) + return false; info = ImageInfo(kFormatHdr, "hdr", "hdr", "image/vnd.radiance"); info.set_size( // std::stol(x_str), //