Skip to content

Commit

Permalink
Fix resolution parsing issue in HDR image header reading
Browse files Browse the repository at this point in the history
- Added safety checks  for string to integer conversion.
  • Loading branch information
dehua committed Jul 12, 2024
1 parent d1e38b6 commit fb1365c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion include/imageinfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down Expand Up @@ -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), //
Expand Down

0 comments on commit fb1365c

Please sign in to comment.