Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions include/exiv2/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,17 @@ class EXIV2API Image {
@param bTestValid - tests that iccProfile contains credible data
*/
virtual void setIccProfile(DataBuf&& iccProfile, bool bTestValid = true);
/*!
@brief Append more bytes to the iccProfile.
@param bytes array of bytes to append
@param size number of bytes to append
@param bTestValid - tests that iccProfile contains credible data
*/
virtual void appendIccProfile(const uint8_t* bytes, size_t size, bool bTestValid);
/*!
@brief Throw an exception if the size at the beginning of the iccProfile isn't correct.
*/
virtual void checkIccProfile();
/*!
@brief Erase iccProfile. the profile is not removed from
the actual image until the writeMetadata() method is called.
Expand Down
29 changes: 21 additions & 8 deletions src/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,16 +625,29 @@ void Image::setComment(const std::string& comment) {
}

void Image::setIccProfile(Exiv2::DataBuf&& iccProfile, bool bTestValid) {
iccProfile_ = std::move(iccProfile);
if (bTestValid) {
if (iccProfile.size() < sizeof(long)) {
throw Error(ErrorCode::kerInvalidIccProfile);
}
const size_t size = iccProfile.read_uint32(0, bigEndian);
if (size != iccProfile.size()) {
throw Error(ErrorCode::kerInvalidIccProfile);
}
checkIccProfile();
}
}

void Image::appendIccProfile(const uint8_t* bytes, size_t size, bool bTestValid) {
const size_t start = iccProfile_.size();
iccProfile_.resize(Safe::add(start, size));
memcpy(iccProfile_.data(start), bytes, size);
if (bTestValid) {
checkIccProfile();
}
}

void Image::checkIccProfile() {
if (iccProfile_.size() < sizeof(long)) {
throw Error(ErrorCode::kerInvalidIccProfile);
}
const size_t size = iccProfile_.read_uint32(0, bigEndian);
if (size != iccProfile_.size()) {
throw Error(ErrorCode::kerInvalidIccProfile);
}
iccProfile_ = std::move(iccProfile);
}

void Image::clearIccProfile() {
Expand Down
7 changes: 1 addition & 6 deletions src/jpgimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,7 @@ void JpegBase::readMetadata() {
icc_size = s;
}

DataBuf profile(Safe::add(iccProfile_.size(), icc_size));
if (!iccProfile_.empty()) {
std::copy(iccProfile_.begin(), iccProfile_.end(), profile.begin());
}
std::copy_n(buf.c_data(2 + 14), icc_size, profile.data() + iccProfile_.size());
setIccProfile(std::move(profile), chunk == chunks);
appendIccProfile(buf.c_data(2 + 14), icc_size, chunk == chunks);
} else if (pixelHeight_ == 0 && inRange2(marker, sof0_, sof3_, sof5_, sof15_)) {
// We hit a SOFn (start-of-frame) marker
if (size < 8) {
Expand Down
Loading