From fb1365c76c76a149f0cbd233af82c562819bd429 Mon Sep 17 00:00:00 2001 From: dehua Date: Fri, 12 Jul 2024 18:38:09 +0800 Subject: [PATCH 1/2] 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), // From 8f8c3e63eb9a540c0ed217bc6a40324b54121dbe Mon Sep 17 00:00:00 2001 From: Weihang Ding <798047000@qq.com> Date: Sun, 14 Jul 2024 13:21:51 +0800 Subject: [PATCH 2/2] Fix code style --- include/imageinfo.hpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/include/imageinfo.hpp b/include/imageinfo.hpp index 1cfa48c..13db0bb 100644 --- a/include/imageinfo.hpp +++ b/include/imageinfo.hpp @@ -430,6 +430,10 @@ class ImageInfo { Error error_ = kNoError; }; +inline bool is_numeric(const std::string &str) { + return !str.empty() && std::all_of(str.begin(), str.end(), ::isdigit); +} + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // https://nokiatech.github.io/heif/technical.html @@ -642,9 +646,7 @@ 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/ @@ -703,8 +705,7 @@ 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; + 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), //