Don't crash if s > size.

This commit is contained in:
Kevin Backhouse 2021-06-23 22:39:31 +01:00 committed by Christoph Hasse
parent c310e2c41f
commit f724f4e2fc

View File

@ -1228,13 +1228,15 @@ namespace Exiv2 {
std::memset(buf.pData_, 0x0, buf.size_);
uint16_t len = 0;
for (auto&& exif : exifData) {
if (exif.ifdId() != ifdId)
continue;
const uint16_t s = exif.tag() * 2 + static_cast<uint16_t>(exif.size());
assert(s <= size);
if (len < s) len = s;
exif.copy(buf.pData_ + exif.tag() * 2, byteOrder);
if (s <= size) {
if (len < s) len = s;
exif.copy(buf.pData_ + exif.tag() * 2, byteOrder);
}
}
// Round the size to make it even.
buf.size_ = len + len%2;