diff --git a/src/jp2image.cpp b/src/jp2image.cpp index 5fce19b4..20727844 100644 --- a/src/jp2image.cpp +++ b/src/jp2image.cpp @@ -37,6 +37,7 @@ #include "error.hpp" #include "futils.hpp" #include "types.hpp" +#include "safe_op.hpp" // + standard includes #include @@ -265,15 +266,16 @@ namespace Exiv2 std::cout << "Exiv2::Jp2Image::readMetadata: " << "Color data found" << std::endl; #endif + const long pad = 3 ; // 3 padding bytes 2 0 0 - DataBuf data(subBox.length+8); + DataBuf data(Safe::add(subBox.length, static_cast(8))); io_->read(data.pData_,data.size_); const long iccLength = getULong(data.pData_+pad, bigEndian); // subtracting pad from data.size_ is safe: // size_ is at least 8 and pad = 3 if (iccLength > data.size_ - pad) { throw Error(58); - } + } DataBuf icc(iccLength); ::memcpy(icc.pData_,data.pData_+pad,icc.size_); #ifdef DEBUG