Fixed test whether data area is outside of the data buffer (partially tested).

v0.27.3
Andreas Huggel 17 years ago
parent ec451c36ea
commit fcd7b2ca45

@ -561,9 +561,14 @@ namespace Action {
} }
else { else {
Exiv2::DataBuf buf = exifThumb.copy(); Exiv2::DataBuf buf = exifThumb.copy();
if (buf.size_ == 0) {
std::cout << _("None");
}
else {
std::cout << exifThumb.mimeType() << ", " std::cout << exifThumb.mimeType() << ", "
<< buf.size_ << " " << _("Bytes"); << buf.size_ << " " << _("Bytes");
} }
}
std::cout << std::endl; std::cout << std::endl;
// Copyright // Copyright
@ -1084,10 +1089,12 @@ namespace Action {
if (dontOverwrite(thumbPath)) return 0; if (dontOverwrite(thumbPath)) return 0;
if (Params::instance().verbose_) { if (Params::instance().verbose_) {
Exiv2::DataBuf buf = exifThumb.copy(); Exiv2::DataBuf buf = exifThumb.copy();
if (buf.size_ != 0) {
std::cout << _("Writing thumbnail") << " (" << exifThumb.mimeType() << ", " std::cout << _("Writing thumbnail") << " (" << exifThumb.mimeType() << ", "
<< buf.size_ << " " << _("Bytes") << ") " << _("to file") << " " << buf.size_ << " " << _("Bytes") << ") " << _("to file") << " "
<< thumbPath << std::endl; << thumbPath << std::endl;
} }
}
rc = exifThumb.writeFile(thumb); rc = exifThumb.writeFile(thumb);
if (rc == 0) { if (rc == 0) {
std::cerr << path_ << ": " << _("Exif data doesn't contain a thumbnail\n"); std::cerr << path_ << ": " << _("Exif data doesn't contain a thumbnail\n");

@ -282,6 +282,7 @@ namespace Exiv2 {
if (thumbnail.get() == 0) return 0; if (thumbnail.get() == 0) return 0;
std::string name = path + thumbnail->extension(); std::string name = path + thumbnail->extension();
DataBuf buf(thumbnail->copy(exifData_)); DataBuf buf(thumbnail->copy(exifData_));
if (buf.size_ == 0) return 0;
return Exiv2::writeFile(buf, name); return Exiv2::writeFile(buf, name);
} }

@ -285,32 +285,34 @@ namespace Exiv2 {
#endif #endif
return; return;
} }
long size = 0; uint32_t size = 0;
for (long i = 0; i < pSize->count(); ++i) { for (int i = 0; i < pSize->count(); ++i) {
size += pSize->toLong(i); size += static_cast<uint32_t>(pSize->toLong(i));
} }
long offset = pValue()->toLong(0); uint32_t offset = static_cast<uint32_t>(pValue()->toLong(0));
// Todo: Remove limitation of JPEG writer: strips must be contiguous // Todo: Remove limitation of JPEG writer: strips must be contiguous
// Until then we check: last offset + last size - first offset == size? // Until then we check: last offset + last size - first offset == size?
if ( pValue()->toLong(pValue()->count()-1) if ( static_cast<uint32_t>(pValue()->toLong(pValue()->count()-1))
+ pSize->toLong(pSize->count()-1) + static_cast<uint32_t>(pSize->toLong(pSize->count()-1))
- offset != size) { - offset != size) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: " std::cerr << "Warning: "
<< "Directory " << tiffGroupName(group()) << "Directory " << tiffGroupName(group())
<< ", entry 0x" << std::setw(4) << ", entry 0x" << std::setw(4)
<< std::setfill('0') << std::hex << tag() << std::setfill('0') << std::hex << tag()
<< " Data area is not contiguous, ignoring it.\n"; << ": Data area is not contiguous, ignoring it.\n";
#endif #endif
return; return;
} }
if (baseOffset + offset + size > sizeData) { if ( offset > sizeData
|| size > sizeData
|| baseOffset + offset > sizeData - size) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: " std::cerr << "Warning: "
<< "Directory " << tiffGroupName(group()) << "Directory " << tiffGroupName(group())
<< ", entry 0x" << std::setw(4) << ", entry 0x" << std::setw(4)
<< std::setfill('0') << std::hex << tag() << std::setfill('0') << std::hex << tag()
<< " Data area exceeds data buffer, ignoring it.\n"; << ": Data area exceeds data buffer, ignoring it.\n";
#endif #endif
return; return;
} }
@ -339,24 +341,26 @@ namespace Exiv2 {
return; return;
} }
for (int i = 0; i < pValue()->count(); ++i) { for (int i = 0; i < pValue()->count(); ++i) {
const byte* pStrip = pData + baseOffset + pValue()->toLong(i); const uint32_t offset = static_cast<uint32_t>(pValue()->toLong(i));
const uint32_t stripSize = static_cast<uint32_t>(pSize->toLong(i)); const byte* pStrip = pData + baseOffset + offset;
if ( stripSize > 0 const uint32_t size = static_cast<uint32_t>(pSize->toLong(i));
&& pData + sizeData > pStrip
&& static_cast<uint32_t>(pData + sizeData - pStrip) >= stripSize) { if ( offset > sizeData
strips_.push_back(std::make_pair(pStrip, stripSize)); || size > sizeData
} || baseOffset + offset > sizeData - size) {
#ifndef SUPPRESS_WARNINGS #ifndef SUPPRESS_WARNINGS
else {
std::cerr << "Warning: " std::cerr << "Warning: "
<< "Directory " << tiffGroupName(group()) << "Directory " << tiffGroupName(group())
<< ", entry 0x" << std::setw(4) << ", entry 0x" << std::setw(4)
<< std::setfill('0') << std::hex << tag() << std::setfill('0') << std::hex << tag()
<< ": Strip " << std::dec << i << ": Strip " << std::dec << i
<< " is outside of the data area; ignored.\n"; << " is outside of the data area; ignored.\n";
}
#endif #endif
} }
else if (size != 0) {
strips_.push_back(std::make_pair(pStrip, size));
}
}
} // TiffImageEntry::setStrips } // TiffImageEntry::setStrips
TiffComponent* TiffComponent::addPath(uint16_t tag, TiffPath& tiffPath) TiffComponent* TiffComponent::addPath(uint16_t tag, TiffPath& tiffPath)

Loading…
Cancel
Save