Skip to content

Commit

Permalink
Check that findKey didn't return end().
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinbackhouse authored and hassec committed Jul 5, 2021
1 parent 98fb218 commit c2b5211
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 23 deletions.
33 changes: 18 additions & 15 deletions src/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,16 +669,17 @@ namespace Exiv2 {

if (subsecTag) {
auto subsec_pos = exifData_->findKey(ExifKey(subsecTag));
if ( subsec_pos != exifData_->end()
&& subsec_pos->typeId() == asciiString) {
std::string ss = subsec_pos->toString();
if (!ss.empty()) {
bool ok = false;
stringTo<long>(ss, ok);
if (ok) subsec = std::string(".") + ss;
if (subsec_pos != exifData_->end()) {
if (subsec_pos->typeId() == asciiString) {
std::string ss = subsec_pos->toString();
if (!ss.empty()) {
bool ok = false;
stringTo<long>(ss, ok);
if (ok) subsec = std::string(".") + ss;
}
}
if (erase_) exifData_->erase(subsec_pos);
}
if (erase_) exifData_->erase(subsec_pos);
}

if (subsec.size() > 10) subsec = subsec.substr(0, 10);
Expand Down Expand Up @@ -1029,18 +1030,20 @@ namespace Exiv2 {
#endif
}
pos = xmpData_->findKey(XmpKey(std::string(from) + "/exif:RedEyeMode"));
if (pos != xmpData_->end() && pos->count() > 0) {
int red = pos->toLong();
if (pos->value().ok())
value |= (red & 1) << 6;
if (pos != xmpData_->end()) {
if (pos->count() > 0) {
int red = pos->toLong();
if (pos->value().ok())
value |= (red & 1) << 6;
#ifndef SUPPRESS_WARNINGS
else
EXV_WARNING << "Failed to convert " << std::string(from) + "/exif:RedEyeMode" << " to " << to << "\n";
else
EXV_WARNING << "Failed to convert " << std::string(from) + "/exif:RedEyeMode" << " to " << to << "\n";
#endif
}
if (erase_) xmpData_->erase(pos);
}

(*exifData_)[to] = value;
if (erase_) xmpData_->erase(pos);
}

void Converter::cnvXmpGPSCoord(const char* from, const char* to)
Expand Down
12 changes: 10 additions & 2 deletions src/crwimage_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1079,8 +1079,16 @@ namespace Exiv2 {
if (ed2 != edEnd) size += ed2->size();
if (size != 0) {
DataBuf buf(size);
if (ed1 != edEnd) ed1->copy(buf.pData_, pHead->byteOrder());
if (ed2 != edEnd) ed2->copy(buf.pData_ + ed1->size(), pHead->byteOrder());
long pos = 0;
if (ed1 != edEnd) {
ed1->copy(buf.pData_, pHead->byteOrder());
pos += ed1->size();
}
if (ed2 != edEnd) {
ed2->copy(buf.pData_ + pos, pHead->byteOrder());
pos += ed2->size();
}
assert(pos == size);
pHead->add(pCrwMapping->crwTagId_, pCrwMapping->crwDir_, buf);
}
else {
Expand Down
4 changes: 2 additions & 2 deletions src/exif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,8 @@ namespace Exiv2 {
ExifKey exifKey(key);
auto pos = findKey(exifKey);
if (pos == end()) {
add(Exifdatum(exifKey));
pos = findKey(exifKey);
exifMetadata_.push_back(Exifdatum(exifKey));
return exifMetadata_.back();
}
return *pos;
}
Expand Down
4 changes: 2 additions & 2 deletions src/iptc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ namespace Exiv2 {
IptcKey iptcKey(key);
auto pos = findKey(iptcKey);
if (pos == end()) {
add(Iptcdatum(iptcKey));
pos = findKey(iptcKey);
iptcMetadata_.push_back(Iptcdatum(iptcKey));
return iptcMetadata_.back();
}
return *pos;
}
Expand Down
4 changes: 2 additions & 2 deletions src/xmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ namespace Exiv2 {
XmpKey xmpKey(key);
auto pos = findKey(xmpKey);
if (pos == end()) {
add(Xmpdatum(xmpKey));
pos = findKey(xmpKey);
xmpMetadata_.push_back(Xmpdatum(xmpKey));
return xmpMetadata_.back();
}
return *pos;
}
Expand Down

0 comments on commit c2b5211

Please sign in to comment.