Remove useless static_casts
This commit is contained in:
parent
ae4df71233
commit
d7f35e33f0
@ -937,10 +937,10 @@ int Params::nonoption(const std::string& argv) {
|
|||||||
return rc;
|
return rc;
|
||||||
} // Params::nonoption
|
} // Params::nonoption
|
||||||
|
|
||||||
static int readFileToBuf(FILE* f, Exiv2::DataBuf& buf) {
|
static size_t readFileToBuf(FILE* f, Exiv2::DataBuf& buf) {
|
||||||
const int buff_size = 4 * 1028;
|
const int buff_size = 4 * 1028;
|
||||||
std::vector<Exiv2::byte> bytes(buff_size);
|
std::vector<Exiv2::byte> bytes(buff_size);
|
||||||
int nBytes = 0;
|
size_t nBytes = 0;
|
||||||
bool more{true};
|
bool more{true};
|
||||||
std::array<char, buff_size> buff;
|
std::array<char, buff_size> buff;
|
||||||
while (more) {
|
while (more) {
|
||||||
|
|||||||
@ -64,7 +64,7 @@ class EXIV2API WebPImage : public Image {
|
|||||||
void doWriteMetadata(BasicIo& outIo);
|
void doWriteMetadata(BasicIo& outIo);
|
||||||
//! @name NOT Implemented
|
//! @name NOT Implemented
|
||||||
//@{
|
//@{
|
||||||
static long getHeaderOffset(const byte* data, long data_size, const byte* header, long header_size);
|
static long getHeaderOffset(const byte* data, size_t data_size, const byte* header, size_t header_size);
|
||||||
static bool equalsWebPTag(Exiv2::DataBuf& buf, const char* str);
|
static bool equalsWebPTag(Exiv2::DataBuf& buf, const char* str);
|
||||||
void debugPrintHex(byte* data, long size);
|
void debugPrintHex(byte* data, long size);
|
||||||
void decodeChunks(long filesize);
|
void decodeChunks(long filesize);
|
||||||
|
|||||||
@ -728,7 +728,7 @@ void MemIo::transfer(BasicIo& src) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t MemIo::write(BasicIo& src) {
|
size_t MemIo::write(BasicIo& src) {
|
||||||
if (static_cast<BasicIo*>(this) == &src)
|
if (this == &src)
|
||||||
return 0;
|
return 0;
|
||||||
if (!src.isopen())
|
if (!src.isopen())
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -506,7 +506,7 @@ void BmffImage::parseTiff(uint32_t root_tag, uint64_t length) {
|
|||||||
if (length > 8) {
|
if (length > 8) {
|
||||||
enforce(length - 8 <= io_->size() - io_->tell(), ErrorCode::kerCorruptedMetadata);
|
enforce(length - 8 <= io_->size() - io_->tell(), ErrorCode::kerCorruptedMetadata);
|
||||||
enforce(length - 8 <= std::numeric_limits<uint64_t>::max(), ErrorCode::kerCorruptedMetadata);
|
enforce(length - 8 <= std::numeric_limits<uint64_t>::max(), ErrorCode::kerCorruptedMetadata);
|
||||||
DataBuf data(static_cast<size_t>(length) - 8);
|
DataBuf data(static_cast<size_t>(length - 8u));
|
||||||
const size_t bufRead = io_->read(data.data(), data.size());
|
const size_t bufRead = io_->read(data.data(), data.size());
|
||||||
|
|
||||||
if (io_->error())
|
if (io_->error())
|
||||||
@ -514,8 +514,7 @@ void BmffImage::parseTiff(uint32_t root_tag, uint64_t length) {
|
|||||||
if (bufRead != data.size())
|
if (bufRead != data.size())
|
||||||
throw Error(ErrorCode::kerInputDataReadFailed);
|
throw Error(ErrorCode::kerInputDataReadFailed);
|
||||||
|
|
||||||
Internal::TiffParserWorker::decode(exifData(), iptcData(), xmpData(), data.c_data(),
|
Internal::TiffParserWorker::decode(exifData(), iptcData(), xmpData(), data.c_data(), data.size(), root_tag,
|
||||||
static_cast<uint32_t>(data.size()), root_tag,
|
|
||||||
Internal::TiffMapping::findDecoder);
|
Internal::TiffMapping::findDecoder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -526,13 +525,12 @@ void BmffImage::parseXmp(uint64_t length, uint64_t start) {
|
|||||||
enforce(length <= io_->size() - start, ErrorCode::kerCorruptedMetadata);
|
enforce(length <= io_->size() - start, ErrorCode::kerCorruptedMetadata);
|
||||||
|
|
||||||
long restore = io_->tell();
|
long restore = io_->tell();
|
||||||
enforce(start <= std::numeric_limits<uint64_t>::max(), ErrorCode::kerCorruptedMetadata);
|
|
||||||
io_->seek(static_cast<long>(start), BasicIo::beg);
|
io_->seek(static_cast<long>(start), BasicIo::beg);
|
||||||
|
|
||||||
enforce(length < std::numeric_limits<uint64_t>::max(), ErrorCode::kerCorruptedMetadata);
|
size_t lengthSizeT = static_cast<size_t>(length);
|
||||||
DataBuf xmp(static_cast<size_t>(length + 1));
|
DataBuf xmp(lengthSizeT + 1);
|
||||||
xmp.write_uint8(static_cast<size_t>(length), 0); // ensure xmp is null terminated!
|
xmp.write_uint8(lengthSizeT, 0); // ensure xmp is null terminated!
|
||||||
if (io_->read(xmp.data(), static_cast<size_t>(length)) != length)
|
if (io_->read(xmp.data(), lengthSizeT) != lengthSizeT)
|
||||||
throw Error(ErrorCode::kerInputDataReadFailed);
|
throw Error(ErrorCode::kerInputDataReadFailed);
|
||||||
if (io_->error())
|
if (io_->error())
|
||||||
throw Error(ErrorCode::kerFailedToReadImageData);
|
throw Error(ErrorCode::kerFailedToReadImageData);
|
||||||
@ -554,7 +552,7 @@ void BmffImage::parseCr3Preview(DataBuf& data, std::ostream& out, bool bTrace, u
|
|||||||
enforce(here >= 0 && here <= std::numeric_limits<long>::max() - static_cast<long>(relative_position),
|
enforce(here >= 0 && here <= std::numeric_limits<long>::max() - static_cast<long>(relative_position),
|
||||||
ErrorCode::kerCorruptedMetadata);
|
ErrorCode::kerCorruptedMetadata);
|
||||||
NativePreview nativePreview;
|
NativePreview nativePreview;
|
||||||
nativePreview.position_ = here + static_cast<long>(relative_position);
|
nativePreview.position_ = here + relative_position;
|
||||||
nativePreview.width_ = data.read_uint16(width_offset, endian_);
|
nativePreview.width_ = data.read_uint16(width_offset, endian_);
|
||||||
nativePreview.height_ = data.read_uint16(height_offset, endian_);
|
nativePreview.height_ = data.read_uint16(height_offset, endian_);
|
||||||
nativePreview.size_ = data.read_uint32(size_offset, endian_);
|
nativePreview.size_ = data.read_uint32(size_offset, endian_);
|
||||||
|
|||||||
@ -244,7 +244,7 @@ void CiffDirectory::readDirectory(const byte* pData, size_t size, ByteOrder byte
|
|||||||
std::cout << "Directory at offset " << std::dec << o << ", " << count << " entries \n";
|
std::cout << "Directory at offset " << std::dec << o << ", " << count << " entries \n";
|
||||||
#endif
|
#endif
|
||||||
o += 2;
|
o += 2;
|
||||||
if (static_cast<uint32_t>(count) * 10 > size - o)
|
if (count * 10u > size - o)
|
||||||
throw Error(ErrorCode::kerCorruptedMetadata);
|
throw Error(ErrorCode::kerCorruptedMetadata);
|
||||||
|
|
||||||
for (uint16_t i = 0; i < count; ++i) {
|
for (uint16_t i = 0; i < count; ++i) {
|
||||||
|
|||||||
@ -602,7 +602,7 @@ void Image::setComment(std::string_view comment) {
|
|||||||
|
|
||||||
void Image::setIccProfile(Exiv2::DataBuf&& iccProfile, bool bTestValid) {
|
void Image::setIccProfile(Exiv2::DataBuf&& iccProfile, bool bTestValid) {
|
||||||
if (bTestValid) {
|
if (bTestValid) {
|
||||||
if (iccProfile.size() < static_cast<long>(sizeof(long))) {
|
if (iccProfile.size() < sizeof(long)) {
|
||||||
throw Error(ErrorCode::kerInvalidIccProfile);
|
throw Error(ErrorCode::kerInvalidIccProfile);
|
||||||
}
|
}
|
||||||
const size_t size = iccProfile.read_uint32(0, bigEndian);
|
const size_t size = iccProfile.read_uint32(0, bigEndian);
|
||||||
|
|||||||
@ -106,7 +106,7 @@ void MrwImage::readMetadata() {
|
|||||||
io_->read(buf.data(), buf.size());
|
io_->read(buf.data(), buf.size());
|
||||||
enforce(!io_->error() && !io_->eof(), ErrorCode::kerFailedToReadImageData);
|
enforce(!io_->error() && !io_->eof(), ErrorCode::kerFailedToReadImageData);
|
||||||
|
|
||||||
ByteOrder bo = TiffParser::decode(exifData_, iptcData_, xmpData_, buf.c_data(), static_cast<uint32_t>(buf.size()));
|
ByteOrder bo = TiffParser::decode(exifData_, iptcData_, xmpData_, buf.c_data(), buf.size());
|
||||||
setByteOrder(bo);
|
setByteOrder(bo);
|
||||||
} // MrwImage::readMetadata
|
} // MrwImage::readMetadata
|
||||||
|
|
||||||
|
|||||||
@ -90,13 +90,13 @@ void PgfImage::readMetadata() {
|
|||||||
// And now, the most interesting, the user data byte array where metadata are stored as small image.
|
// And now, the most interesting, the user data byte array where metadata are stored as small image.
|
||||||
|
|
||||||
enforce(headerSize <= std::numeric_limits<size_t>::max() - 8, ErrorCode::kerCorruptedMetadata);
|
enforce(headerSize <= std::numeric_limits<size_t>::max() - 8, ErrorCode::kerCorruptedMetadata);
|
||||||
long size = static_cast<long>(headerSize) + 8 - io_->tell();
|
size_t size = headerSize + 8 - static_cast<size_t>(io_->tell());
|
||||||
|
|
||||||
#ifdef EXIV2_DEBUG_MESSAGES
|
#ifdef EXIV2_DEBUG_MESSAGES
|
||||||
std::cout << "Exiv2::PgfImage::readMetadata: Found Image data (" << size << " bytes)\n";
|
std::cout << "Exiv2::PgfImage::readMetadata: Found Image data (" << size << " bytes)\n";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (size < 0 || static_cast<size_t>(size) > io_->size())
|
if (size > io_->size())
|
||||||
throw Error(ErrorCode::kerInputDataReadFailed);
|
throw Error(ErrorCode::kerInputDataReadFailed);
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -31,7 +31,7 @@ bool cmpPreviewProperties(const PreviewProperties &lhs, const PreviewProperties
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Decode a Hex string.
|
/// @brief Decode a Hex string.
|
||||||
DataBuf decodeHex(const byte *src, long srcSize);
|
DataBuf decodeHex(const byte *src, size_t srcSize);
|
||||||
|
|
||||||
/// @brief Decode a Base64 string.
|
/// @brief Decode a Base64 string.
|
||||||
DataBuf decodeBase64(const std::string &src);
|
DataBuf decodeBase64(const std::string &src);
|
||||||
@ -409,12 +409,12 @@ DataBuf LoaderNative::getData() const {
|
|||||||
return {data + nativePreview_.position_, nativePreview_.size_};
|
return {data + nativePreview_.position_, nativePreview_.size_};
|
||||||
}
|
}
|
||||||
if (nativePreview_.filter_ == "hex-ai7thumbnail-pnm") {
|
if (nativePreview_.filter_ == "hex-ai7thumbnail-pnm") {
|
||||||
const DataBuf ai7thumbnail = decodeHex(data + nativePreview_.position_, static_cast<long>(nativePreview_.size_));
|
const DataBuf ai7thumbnail = decodeHex(data + nativePreview_.position_, nativePreview_.size_);
|
||||||
const DataBuf rgb = decodeAi7Thumbnail(ai7thumbnail);
|
const DataBuf rgb = decodeAi7Thumbnail(ai7thumbnail);
|
||||||
return makePnm(width_, height_, rgb);
|
return makePnm(width_, height_, rgb);
|
||||||
}
|
}
|
||||||
if (nativePreview_.filter_ == "hex-irb") {
|
if (nativePreview_.filter_ == "hex-irb") {
|
||||||
const DataBuf psData = decodeHex(data + nativePreview_.position_, static_cast<long>(nativePreview_.size_));
|
const DataBuf psData = decodeHex(data + nativePreview_.position_, nativePreview_.size_);
|
||||||
const byte *record;
|
const byte *record;
|
||||||
uint32_t sizeHdr = 0;
|
uint32_t sizeHdr = 0;
|
||||||
uint32_t sizeData = 0;
|
uint32_t sizeData = 0;
|
||||||
@ -479,7 +479,7 @@ LoaderExifJpeg::LoaderExifJpeg(PreviewId id, const Image &image, int parIdx) : L
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Safe::add(offset_, size_) > static_cast<uint32_t>(image_.io().size()))
|
if (Safe::add(offset_, size_) > image_.io().size())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
valid_ = true;
|
valid_ = true;
|
||||||
@ -648,7 +648,7 @@ LoaderTiff::LoaderTiff(PreviewId id, const Image &image, int parIdx) :
|
|||||||
if (offsetCount != pos->value().count())
|
if (offsetCount != pos->value().count())
|
||||||
return;
|
return;
|
||||||
for (size_t i = 0; i < offsetCount; i++) {
|
for (size_t i = 0; i < offsetCount; i++) {
|
||||||
size_ += pos->toUint32(static_cast<long>(i));
|
size_ += pos->toUint32(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size_ == 0)
|
if (size_ == 0)
|
||||||
@ -727,7 +727,7 @@ DataBuf LoaderTiff::getData() const {
|
|||||||
dataValue.setDataArea(base + offset, size);
|
dataValue.setDataArea(base + offset, size);
|
||||||
} else {
|
} else {
|
||||||
// FIXME: the buffer is probably copied twice, it should be optimized
|
// FIXME: the buffer is probably copied twice, it should be optimized
|
||||||
enforce(size_ <= static_cast<uint32_t>(io.size()), ErrorCode::kerCorruptedMetadata);
|
enforce(size_ <= io.size(), ErrorCode::kerCorruptedMetadata);
|
||||||
DataBuf buf(size_);
|
DataBuf buf(size_);
|
||||||
uint32_t idxBuf = 0;
|
uint32_t idxBuf = 0;
|
||||||
for (size_t i = 0; i < sizes.count(); i++) {
|
for (size_t i = 0; i < sizes.count(); i++) {
|
||||||
@ -792,7 +792,7 @@ LoaderXmpJpeg::LoaderXmpJpeg(PreviewId id, const Image &image, int parIdx) : Loa
|
|||||||
width_ = widthDatum->toUint32();
|
width_ = widthDatum->toUint32();
|
||||||
height_ = heightDatum->toUint32();
|
height_ = heightDatum->toUint32();
|
||||||
preview_ = decodeBase64(imageDatum->toString());
|
preview_ = decodeBase64(imageDatum->toString());
|
||||||
size_ = static_cast<uint32_t>(preview_.size());
|
size_ = preview_.size();
|
||||||
valid_ = true;
|
valid_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -817,7 +817,7 @@ bool LoaderXmpJpeg::readDimensions() {
|
|||||||
return valid();
|
return valid();
|
||||||
}
|
}
|
||||||
|
|
||||||
DataBuf decodeHex(const byte *src, long srcSize) {
|
DataBuf decodeHex(const byte *src, size_t srcSize) {
|
||||||
// create decoding table
|
// create decoding table
|
||||||
byte invalid = 16;
|
byte invalid = 16;
|
||||||
std::array<byte, 256> decodeHexTable;
|
std::array<byte, 256> decodeHexTable;
|
||||||
@ -831,17 +831,17 @@ DataBuf decodeHex(const byte *src, long srcSize) {
|
|||||||
|
|
||||||
// calculate dest size
|
// calculate dest size
|
||||||
long validSrcSize = 0;
|
long validSrcSize = 0;
|
||||||
for (long srcPos = 0; srcPos < srcSize; srcPos++) {
|
for (size_t srcPos = 0; srcPos < srcSize; srcPos++) {
|
||||||
if (decodeHexTable[src[srcPos]] != invalid)
|
if (decodeHexTable[src[srcPos]] != invalid)
|
||||||
validSrcSize++;
|
validSrcSize++;
|
||||||
}
|
}
|
||||||
const long destSize = validSrcSize / 2;
|
const size_t destSize = validSrcSize / 2;
|
||||||
|
|
||||||
// allocate dest buffer
|
// allocate dest buffer
|
||||||
DataBuf dest(destSize);
|
DataBuf dest(destSize);
|
||||||
|
|
||||||
// decode
|
// decode
|
||||||
for (long srcPos = 0, destPos = 0; destPos < destSize; destPos++) {
|
for (size_t srcPos = 0, destPos = 0; destPos < destSize; destPos++) {
|
||||||
byte buffer = 0;
|
byte buffer = 0;
|
||||||
for (int bufferPos = 1; bufferPos >= 0 && srcPos < srcSize; srcPos++) {
|
for (int bufferPos = 1; bufferPos >= 0 && srcPos < srcSize; srcPos++) {
|
||||||
byte srcValue = decodeHexTable[src[srcPos]];
|
byte srcValue = decodeHexTable[src[srcPos]];
|
||||||
@ -880,7 +880,7 @@ DataBuf decodeBase64(const std::string &src) {
|
|||||||
// allocate dest buffer
|
// allocate dest buffer
|
||||||
if (destSize > LONG_MAX)
|
if (destSize > LONG_MAX)
|
||||||
return {}; // avoid integer overflow
|
return {}; // avoid integer overflow
|
||||||
DataBuf dest(static_cast<long>(destSize));
|
DataBuf dest(destSize);
|
||||||
|
|
||||||
// decode
|
// decode
|
||||||
for (unsigned long srcPos = 0, destPos = 0; destPos < destSize;) {
|
for (unsigned long srcPos = 0, destPos = 0; destPos < destSize;) {
|
||||||
@ -901,7 +901,7 @@ DataBuf decodeBase64(const std::string &src) {
|
|||||||
|
|
||||||
DataBuf decodeAi7Thumbnail(const DataBuf &src) {
|
DataBuf decodeAi7Thumbnail(const DataBuf &src) {
|
||||||
const byte *colorTable = src.c_data();
|
const byte *colorTable = src.c_data();
|
||||||
const long colorTableSize = 256 * 3;
|
const size_t colorTableSize = 256 * 3;
|
||||||
if (src.size() < colorTableSize) {
|
if (src.size() < colorTableSize) {
|
||||||
#ifndef SUPPRESS_WARNINGS
|
#ifndef SUPPRESS_WARNINGS
|
||||||
EXV_WARNING << "Invalid size of AI7 thumbnail: " << src.size() << "\n";
|
EXV_WARNING << "Invalid size of AI7 thumbnail: " << src.size() << "\n";
|
||||||
@ -909,10 +909,10 @@ DataBuf decodeAi7Thumbnail(const DataBuf &src) {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
const byte *imageData = src.c_data(colorTableSize);
|
const byte *imageData = src.c_data(colorTableSize);
|
||||||
const long imageDataSize = static_cast<long>(src.size()) - colorTableSize;
|
const size_t imageDataSize = src.size() - colorTableSize;
|
||||||
const bool rle = (imageDataSize >= 3 && imageData[0] == 'R' && imageData[1] == 'L' && imageData[2] == 'E');
|
const bool rle = (imageDataSize >= 3 && imageData[0] == 'R' && imageData[1] == 'L' && imageData[2] == 'E');
|
||||||
std::string dest;
|
std::string dest;
|
||||||
for (long i = rle ? 3 : 0; i < imageDataSize;) {
|
for (size_t i = rle ? 3 : 0; i < imageDataSize;) {
|
||||||
byte num = 1;
|
byte num = 1;
|
||||||
byte value = imageData[i++];
|
byte value = imageData[i++];
|
||||||
if (rle && value == 0xFD) {
|
if (rle && value == 0xFD) {
|
||||||
@ -1029,8 +1029,8 @@ PreviewPropertiesList PreviewManager::getPreviewProperties() const {
|
|||||||
auto loader = Loader::create(id, image_);
|
auto loader = Loader::create(id, image_);
|
||||||
if (loader && loader->readDimensions()) {
|
if (loader && loader->readDimensions()) {
|
||||||
PreviewProperties props = loader->getProperties();
|
PreviewProperties props = loader->getProperties();
|
||||||
DataBuf buf = loader->getData(); // #16 getPreviewImage()
|
DataBuf buf = loader->getData(); // #16 getPreviewImage()
|
||||||
props.size_ = static_cast<uint32_t>(buf.size()); // update the size
|
props.size_ = buf.size(); // update the size
|
||||||
list.push_back(props);
|
list.push_back(props);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -217,7 +217,7 @@ void PsdImage::readResourceBlock(uint16_t resourceId, uint32_t resourceSize) {
|
|||||||
io_->read(rawIPTC.data(), rawIPTC.size());
|
io_->read(rawIPTC.data(), rawIPTC.size());
|
||||||
if (io_->error() || io_->eof())
|
if (io_->error() || io_->eof())
|
||||||
throw Error(ErrorCode::kerFailedToReadImageData);
|
throw Error(ErrorCode::kerFailedToReadImageData);
|
||||||
if (IptcParser::decode(iptcData_, rawIPTC.c_data(), static_cast<uint32_t>(rawIPTC.size()))) {
|
if (IptcParser::decode(iptcData_, rawIPTC.c_data(), rawIPTC.size())) {
|
||||||
#ifndef SUPPRESS_WARNINGS
|
#ifndef SUPPRESS_WARNINGS
|
||||||
EXV_WARNING << "Failed to decode IPTC metadata.\n";
|
EXV_WARNING << "Failed to decode IPTC metadata.\n";
|
||||||
#endif
|
#endif
|
||||||
@ -484,8 +484,7 @@ void PsdImage::doWriteMetadata(BasicIo& outIo) {
|
|||||||
readTotal = 0;
|
readTotal = 0;
|
||||||
while (readTotal < pResourceSize) {
|
while (readTotal < pResourceSize) {
|
||||||
/// \todo almost same code as in lines 403-410. Factor out & reuse!
|
/// \todo almost same code as in lines 403-410. Factor out & reuse!
|
||||||
size_t toRead = (pResourceSize - readTotal) < lbuf.size() ? static_cast<long>(pResourceSize - readTotal)
|
size_t toRead = (pResourceSize - readTotal) < lbuf.size() ? pResourceSize - readTotal : lbuf.size();
|
||||||
: static_cast<long>(lbuf.size());
|
|
||||||
if (io_->read(lbuf.data(), toRead) != toRead) {
|
if (io_->read(lbuf.data(), toRead) != toRead) {
|
||||||
throw Error(ErrorCode::kerNotAnImage, "Photoshop");
|
throw Error(ErrorCode::kerNotAnImage, "Photoshop");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -217,7 +217,7 @@ void TiffEntryBase::setData(const std::shared_ptr<DataBuf>& buf) {
|
|||||||
size_ = buf->size();
|
size_ = buf->size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TiffEntryBase::setData(byte* pData, uint32_t size, const std::shared_ptr<DataBuf>& storage) {
|
void TiffEntryBase::setData(byte* pData, size_t size, const std::shared_ptr<DataBuf>& storage) {
|
||||||
pData_ = pData;
|
pData_ = pData;
|
||||||
size_ = size;
|
size_ = size;
|
||||||
storage_ = storage;
|
storage_ = storage;
|
||||||
@ -352,7 +352,7 @@ uint32_t TiffIfdMakernote::baseOffset() const {
|
|||||||
return pHeader_->baseOffset(mnOffset_);
|
return pHeader_->baseOffset(mnOffset_);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TiffIfdMakernote::readHeader(const byte* pData, uint32_t size, ByteOrder byteOrder) {
|
bool TiffIfdMakernote::readHeader(const byte* pData, size_t size, ByteOrder byteOrder) {
|
||||||
if (!pHeader_)
|
if (!pHeader_)
|
||||||
return true;
|
return true;
|
||||||
return pHeader_->read(pData, size, byteOrder);
|
return pHeader_->read(pData, size, byteOrder);
|
||||||
|
|||||||
@ -422,7 +422,7 @@ class TiffEntryBase : public TiffComponent {
|
|||||||
you should pass std::shared_ptr<DataBuf>(), which is essentially
|
you should pass std::shared_ptr<DataBuf>(), which is essentially
|
||||||
a nullptr.
|
a nullptr.
|
||||||
*/
|
*/
|
||||||
void setData(byte* pData, uint32_t size, const std::shared_ptr<DataBuf>& storage);
|
void setData(byte* pData, size_t size, const std::shared_ptr<DataBuf>& storage);
|
||||||
/*!
|
/*!
|
||||||
@brief Set the entry's data buffer. A shared_ptr is used to manage the DataBuf
|
@brief Set the entry's data buffer. A shared_ptr is used to manage the DataBuf
|
||||||
because TiffEntryBase has a clone method so it is possible (in theory) for
|
because TiffEntryBase has a clone method so it is possible (in theory) for
|
||||||
@ -1113,7 +1113,7 @@ class TiffIfdMakernote : public TiffComponent {
|
|||||||
|
|
||||||
The default implementation simply returns true.
|
The default implementation simply returns true.
|
||||||
*/
|
*/
|
||||||
bool readHeader(const byte* pData, uint32_t size, ByteOrder byteOrder);
|
bool readHeader(const byte* pData, size_t size, ByteOrder byteOrder);
|
||||||
/*!
|
/*!
|
||||||
@brief Set the byte order for the makernote.
|
@brief Set the byte order for the makernote.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -220,8 +220,7 @@ ByteOrder TiffParser::decode(ExifData& exifData, IptcData& iptcData, XmpData& xm
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TiffParserWorker::decode(exifData, iptcData, xmpData, pData, static_cast<uint32_t>(size), root,
|
return TiffParserWorker::decode(exifData, iptcData, xmpData, pData, size, root, TiffMapping::findDecoder);
|
||||||
TiffMapping::findDecoder);
|
|
||||||
} // TiffParser::decode
|
} // TiffParser::decode
|
||||||
|
|
||||||
WriteMethod TiffParser::encode(BasicIo& io, const byte* pData, size_t size, ByteOrder byteOrder,
|
WriteMethod TiffParser::encode(BasicIo& io, const byte* pData, size_t size, ByteOrder byteOrder,
|
||||||
|
|||||||
@ -310,7 +310,7 @@ void TiffDecoder::decodeIptc(const TiffEntryBase* object) {
|
|||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
getObjData(pData, size, 0x83bb, ifd0Id, object);
|
getObjData(pData, size, 0x83bb, ifd0Id, object);
|
||||||
if (pData) {
|
if (pData) {
|
||||||
if (0 == IptcParser::decode(iptcData_, pData, static_cast<uint32_t>(size))) {
|
if (0 == IptcParser::decode(iptcData_, pData, size)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#ifndef SUPPRESS_WARNINGS
|
#ifndef SUPPRESS_WARNINGS
|
||||||
@ -516,7 +516,7 @@ void TiffEncoder::encodeIptc() {
|
|||||||
} else {
|
} else {
|
||||||
buf = std::move(rawIptc); // Note: This resets rawIptc
|
buf = std::move(rawIptc); // Note: This resets rawIptc
|
||||||
}
|
}
|
||||||
value->read(buf.data(), static_cast<long>(buf.size()), byteOrder_);
|
value->read(buf.data(), buf.size(), byteOrder_);
|
||||||
Exifdatum iptcDatum(iptcNaaKey, value.get());
|
Exifdatum iptcDatum(iptcNaaKey, value.get());
|
||||||
exifData_.add(iptcDatum);
|
exifData_.add(iptcDatum);
|
||||||
pos = exifData_.findKey(irbKey); // needed after add()
|
pos = exifData_.findKey(irbKey); // needed after add()
|
||||||
@ -530,7 +530,7 @@ void TiffEncoder::encodeIptc() {
|
|||||||
exifData_.erase(pos);
|
exifData_.erase(pos);
|
||||||
if (!irbBuf.empty()) {
|
if (!irbBuf.empty()) {
|
||||||
auto value = Value::create(unsignedByte);
|
auto value = Value::create(unsignedByte);
|
||||||
value->read(irbBuf.data(), static_cast<long>(irbBuf.size()), invalidByteOrder);
|
value->read(irbBuf.data(), irbBuf.size(), invalidByteOrder);
|
||||||
Exifdatum iptcDatum(irbKey, value.get());
|
Exifdatum iptcDatum(irbKey, value.get());
|
||||||
exifData_.add(iptcDatum);
|
exifData_.add(iptcDatum);
|
||||||
}
|
}
|
||||||
@ -559,7 +559,7 @@ void TiffEncoder::encodeXmp() {
|
|||||||
if (!xmpPacket.empty()) {
|
if (!xmpPacket.empty()) {
|
||||||
// Set the XMP Exif tag to the new value
|
// Set the XMP Exif tag to the new value
|
||||||
auto value = Value::create(unsignedByte);
|
auto value = Value::create(unsignedByte);
|
||||||
value->read(reinterpret_cast<const byte*>(&xmpPacket[0]), static_cast<long>(xmpPacket.size()), invalidByteOrder);
|
value->read(reinterpret_cast<const byte*>(&xmpPacket[0]), xmpPacket.size(), invalidByteOrder);
|
||||||
Exifdatum xmpDatum(xmpKey, value.get());
|
Exifdatum xmpDatum(xmpKey, value.get());
|
||||||
exifData_.add(xmpDatum);
|
exifData_.add(xmpDatum);
|
||||||
}
|
}
|
||||||
@ -697,7 +697,7 @@ void TiffEncoder::visitBinaryArrayEnd(TiffBinaryArray* object) {
|
|||||||
DataBuf buf = cryptFct(object->tag(), pData, size, pRoot_);
|
DataBuf buf = cryptFct(object->tag(), pData, size, pRoot_);
|
||||||
if (!buf.empty()) {
|
if (!buf.empty()) {
|
||||||
pData = buf.c_data();
|
pData = buf.c_data();
|
||||||
size = static_cast<int32_t>(buf.size());
|
size = buf.size();
|
||||||
}
|
}
|
||||||
if (!object->updOrigDataBuf(pData, size)) {
|
if (!object->updOrigDataBuf(pData, size)) {
|
||||||
setDirty();
|
setDirty();
|
||||||
@ -837,7 +837,7 @@ void TiffEncoder::encodeImageEntry(TiffImageEntry* object, const Exifdatum* datu
|
|||||||
uint32_t sizeTotal = 0;
|
uint32_t sizeTotal = 0;
|
||||||
object->strips_.clear();
|
object->strips_.clear();
|
||||||
for (size_t i = 0; i < pos->count(); ++i) {
|
for (size_t i = 0; i < pos->count(); ++i) {
|
||||||
uint32_t len = pos->toUint32(static_cast<long>(i));
|
uint32_t len = pos->toUint32(i);
|
||||||
object->strips_.emplace_back(zero, len);
|
object->strips_.emplace_back(zero, len);
|
||||||
sizeTotal += len;
|
sizeTotal += len;
|
||||||
}
|
}
|
||||||
@ -1225,12 +1225,12 @@ void TiffReader::visitMnEntry(TiffMnEntry* object) {
|
|||||||
void TiffReader::visitIfdMakernote(TiffIfdMakernote* object) {
|
void TiffReader::visitIfdMakernote(TiffIfdMakernote* object) {
|
||||||
object->setImageByteOrder(byteOrder()); // set the byte order for the image
|
object->setImageByteOrder(byteOrder()); // set the byte order for the image
|
||||||
|
|
||||||
if (!object->readHeader(object->start(), static_cast<uint32_t>(pLast_ - object->start()), byteOrder())) {
|
if (!object->readHeader(object->start(), pLast_ - object->start(), byteOrder())) {
|
||||||
#ifndef SUPPRESS_WARNINGS
|
#ifndef SUPPRESS_WARNINGS
|
||||||
EXV_ERROR << "Failed to read " << groupName(object->ifd_.group()) << " IFD Makernote header.\n";
|
EXV_ERROR << "Failed to read " << groupName(object->ifd_.group()) << " IFD Makernote header.\n";
|
||||||
#ifdef EXIV2_DEBUG_MESSAGES
|
#ifdef EXIV2_DEBUG_MESSAGES
|
||||||
if (static_cast<uint32_t>(pLast_ - object->start()) >= 16) {
|
if (pLast_ - object->start() >= 16u) {
|
||||||
hexdump(std::cerr, object->start(), 16);
|
hexdump(std::cerr, object->start(), 16u);
|
||||||
}
|
}
|
||||||
#endif // EXIV2_DEBUG_MESSAGES
|
#endif // EXIV2_DEBUG_MESSAGES
|
||||||
#endif // SUPPRESS_WARNINGS
|
#endif // SUPPRESS_WARNINGS
|
||||||
@ -1291,10 +1291,10 @@ void TiffReader::readTiffEntry(TiffEntryBase* object) {
|
|||||||
if (count > std::numeric_limits<uint32_t>::max() / typeSize) {
|
if (count > std::numeric_limits<uint32_t>::max() / typeSize) {
|
||||||
throw Error(ErrorCode::kerArithmeticOverflow);
|
throw Error(ErrorCode::kerArithmeticOverflow);
|
||||||
}
|
}
|
||||||
auto size = static_cast<uint32_t>(typeSize * count);
|
size_t size = typeSize * count;
|
||||||
uint32_t offset = getLong(p, byteOrder());
|
uint32_t offset = getLong(p, byteOrder());
|
||||||
byte* pData = p;
|
byte* pData = p;
|
||||||
if (size > 4 && (baseOffset() + offset >= size_ || static_cast<int32_t>(baseOffset()) + offset <= 0)) {
|
if (size > 4 && (baseOffset() + offset >= size_ || baseOffset() + offset <= 0)) {
|
||||||
// #1143
|
// #1143
|
||||||
if (object->tag() == 0x2001 && std::string(groupName(object->group())) == "Sony1") {
|
if (object->tag() == 0x2001 && std::string(groupName(object->group())) == "Sony1") {
|
||||||
// This tag is Exif.Sony1.PreviewImage, which refers to a preview image which is
|
// This tag is Exif.Sony1.PreviewImage, which refers to a preview image which is
|
||||||
@ -1335,7 +1335,7 @@ void TiffReader::readTiffEntry(TiffEntryBase* object) {
|
|||||||
pData = const_cast<byte*>(pData_) + baseOffset() + offset;
|
pData = const_cast<byte*>(pData_) + baseOffset() + offset;
|
||||||
|
|
||||||
// check for size being invalid
|
// check for size being invalid
|
||||||
if (size > static_cast<uint32_t>(pLast_ - pData)) {
|
if (size > static_cast<size_t>(pLast_ - pData)) {
|
||||||
#ifndef SUPPRESS_WARNINGS
|
#ifndef SUPPRESS_WARNINGS
|
||||||
EXV_ERROR << "Upper boundary of data for "
|
EXV_ERROR << "Upper boundary of data for "
|
||||||
<< "directory " << groupName(object->group()) << ", entry 0x" << std::setw(4) << std::setfill('0')
|
<< "directory " << groupName(object->group()) << ", entry 0x" << std::setw(4) << std::setfill('0')
|
||||||
|
|||||||
@ -155,8 +155,8 @@ DataValue* DataValue::clone_() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& DataValue::write(std::ostream& os) const {
|
std::ostream& DataValue::write(std::ostream& os) const {
|
||||||
std::vector<byte>::size_type end = value_.size();
|
size_t end = value_.size();
|
||||||
for (std::vector<byte>::size_type i = 0; i != end; ++i) {
|
for (size_t i = 0; i != end; ++i) {
|
||||||
os << static_cast<int>(value_.at(i));
|
os << static_cast<int>(value_.at(i));
|
||||||
if (i < end - 1)
|
if (i < end - 1)
|
||||||
os << " ";
|
os << " ";
|
||||||
|
|||||||
@ -184,10 +184,8 @@ void WebPImage::doWriteMetadata(BasicIo& outIo) {
|
|||||||
const uint32_t size_u32 = Exiv2::getULong(size_buff, littleEndian);
|
const uint32_t size_u32 = Exiv2::getULong(size_buff, littleEndian);
|
||||||
|
|
||||||
// Check that `size_u32` is safe to cast to `long`.
|
// Check that `size_u32` is safe to cast to `long`.
|
||||||
enforce(size_u32 <= static_cast<size_t>(std::numeric_limits<unsigned int>::max()),
|
enforce(size_u32 <= std::numeric_limits<uint32_t>::max(), Exiv2::ErrorCode::kerCorruptedMetadata);
|
||||||
Exiv2::ErrorCode::kerCorruptedMetadata);
|
DataBuf payload(size_u32);
|
||||||
const auto size = static_cast<long>(size_u32);
|
|
||||||
DataBuf payload(size);
|
|
||||||
io_->readOrThrow(payload.data(), payload.size(), Exiv2::ErrorCode::kerCorruptedMetadata);
|
io_->readOrThrow(payload.data(), payload.size(), Exiv2::ErrorCode::kerCorruptedMetadata);
|
||||||
if (payload.size() % 2) {
|
if (payload.size() % 2) {
|
||||||
byte c = 0;
|
byte c = 0;
|
||||||
@ -200,7 +198,7 @@ void WebPImage::doWriteMetadata(BasicIo& outIo) {
|
|||||||
has_vp8x = true;
|
has_vp8x = true;
|
||||||
}
|
}
|
||||||
if (equalsWebPTag(chunkId, WEBP_CHUNK_HEADER_VP8X) && !has_size) {
|
if (equalsWebPTag(chunkId, WEBP_CHUNK_HEADER_VP8X) && !has_size) {
|
||||||
enforce(size >= 10, Exiv2::ErrorCode::kerCorruptedMetadata);
|
enforce(size_u32 >= 10, Exiv2::ErrorCode::kerCorruptedMetadata);
|
||||||
has_size = true;
|
has_size = true;
|
||||||
byte size_buf[WEBP_TAG_SIZE];
|
byte size_buf[WEBP_TAG_SIZE];
|
||||||
|
|
||||||
@ -229,7 +227,7 @@ void WebPImage::doWriteMetadata(BasicIo& outIo) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (equalsWebPTag(chunkId, WEBP_CHUNK_HEADER_VP8) && !has_size) {
|
if (equalsWebPTag(chunkId, WEBP_CHUNK_HEADER_VP8) && !has_size) {
|
||||||
enforce(size >= 10, Exiv2::ErrorCode::kerCorruptedMetadata);
|
enforce(size_u32 >= 10, Exiv2::ErrorCode::kerCorruptedMetadata);
|
||||||
has_size = true;
|
has_size = true;
|
||||||
byte size_buf[2];
|
byte size_buf[2];
|
||||||
|
|
||||||
@ -247,13 +245,13 @@ void WebPImage::doWriteMetadata(BasicIo& outIo) {
|
|||||||
|
|
||||||
/* Chunk with lossless image data. */
|
/* Chunk with lossless image data. */
|
||||||
if (equalsWebPTag(chunkId, WEBP_CHUNK_HEADER_VP8L) && !has_alpha) {
|
if (equalsWebPTag(chunkId, WEBP_CHUNK_HEADER_VP8L) && !has_alpha) {
|
||||||
enforce(size >= 5, Exiv2::ErrorCode::kerCorruptedMetadata);
|
enforce(size_u32 >= 5, Exiv2::ErrorCode::kerCorruptedMetadata);
|
||||||
if ((payload.read_uint8(4) & WEBP_VP8X_ALPHA_BIT) == WEBP_VP8X_ALPHA_BIT) {
|
if ((payload.read_uint8(4) & WEBP_VP8X_ALPHA_BIT) == WEBP_VP8X_ALPHA_BIT) {
|
||||||
has_alpha = true;
|
has_alpha = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (equalsWebPTag(chunkId, WEBP_CHUNK_HEADER_VP8L) && !has_size) {
|
if (equalsWebPTag(chunkId, WEBP_CHUNK_HEADER_VP8L) && !has_size) {
|
||||||
enforce(size >= 5, Exiv2::ErrorCode::kerCorruptedMetadata);
|
enforce(size_u32 >= 5, Exiv2::ErrorCode::kerCorruptedMetadata);
|
||||||
has_size = true;
|
has_size = true;
|
||||||
byte size_buf_w[2];
|
byte size_buf_w[2];
|
||||||
byte size_buf_h[3];
|
byte size_buf_h[3];
|
||||||
@ -277,13 +275,13 @@ void WebPImage::doWriteMetadata(BasicIo& outIo) {
|
|||||||
|
|
||||||
/* Chunk with animation frame. */
|
/* Chunk with animation frame. */
|
||||||
if (equalsWebPTag(chunkId, WEBP_CHUNK_HEADER_ANMF) && !has_alpha) {
|
if (equalsWebPTag(chunkId, WEBP_CHUNK_HEADER_ANMF) && !has_alpha) {
|
||||||
enforce(size >= 6, Exiv2::ErrorCode::kerCorruptedMetadata);
|
enforce(size_u32 >= 6, Exiv2::ErrorCode::kerCorruptedMetadata);
|
||||||
if ((payload.read_uint8(5) & 0x2) == 0x2) {
|
if ((payload.read_uint8(5) & 0x2) == 0x2) {
|
||||||
has_alpha = true;
|
has_alpha = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (equalsWebPTag(chunkId, WEBP_CHUNK_HEADER_ANMF) && !has_size) {
|
if (equalsWebPTag(chunkId, WEBP_CHUNK_HEADER_ANMF) && !has_size) {
|
||||||
enforce(size >= 12, Exiv2::ErrorCode::kerCorruptedMetadata);
|
enforce(size_u32 >= 12, Exiv2::ErrorCode::kerCorruptedMetadata);
|
||||||
has_size = true;
|
has_size = true;
|
||||||
byte size_buf[WEBP_TAG_SIZE];
|
byte size_buf[WEBP_TAG_SIZE];
|
||||||
|
|
||||||
@ -317,17 +315,15 @@ void WebPImage::doWriteMetadata(BasicIo& outIo) {
|
|||||||
const uint32_t size_u32 = Exiv2::getULong(size_buff, littleEndian);
|
const uint32_t size_u32 = Exiv2::getULong(size_buff, littleEndian);
|
||||||
|
|
||||||
// Check that `size_u32` is safe to cast to `long`.
|
// Check that `size_u32` is safe to cast to `long`.
|
||||||
enforce(size_u32 <= static_cast<size_t>(std::numeric_limits<unsigned int>::max()),
|
enforce(size_u32 <= std::numeric_limits<uint32_t>::max(), Exiv2::ErrorCode::kerCorruptedMetadata);
|
||||||
Exiv2::ErrorCode::kerCorruptedMetadata);
|
|
||||||
const auto size = static_cast<long>(size_u32);
|
|
||||||
|
|
||||||
DataBuf payload(size);
|
DataBuf payload(size_u32);
|
||||||
io_->readOrThrow(payload.data(), size, Exiv2::ErrorCode::kerCorruptedMetadata);
|
io_->readOrThrow(payload.data(), size_u32, Exiv2::ErrorCode::kerCorruptedMetadata);
|
||||||
if (io_->tell() % 2)
|
if (io_->tell() % 2)
|
||||||
io_->seek(+1, BasicIo::cur); // skip pad
|
io_->seek(+1, BasicIo::cur); // skip pad
|
||||||
|
|
||||||
if (equalsWebPTag(chunkId, WEBP_CHUNK_HEADER_VP8X)) {
|
if (equalsWebPTag(chunkId, WEBP_CHUNK_HEADER_VP8X)) {
|
||||||
enforce(size >= 1, Exiv2::ErrorCode::kerCorruptedMetadata);
|
enforce(size_u32 >= 1, Exiv2::ErrorCode::kerCorruptedMetadata);
|
||||||
if (has_icc) {
|
if (has_icc) {
|
||||||
const uint8_t x = payload.read_uint8(0);
|
const uint8_t x = payload.read_uint8(0);
|
||||||
payload.write_uint8(0, x | WEBP_VP8X_ICC_BIT);
|
payload.write_uint8(0, x | WEBP_VP8X_ICC_BIT);
|
||||||
@ -643,26 +639,22 @@ void WebPImage::decodeChunks(long filesize) {
|
|||||||
bool s_header = false;
|
bool s_header = false;
|
||||||
bool le_header = false;
|
bool le_header = false;
|
||||||
bool be_header = false;
|
bool be_header = false;
|
||||||
long pos = getHeaderOffset(payload.c_data(), static_cast<long>(payload.size()),
|
long pos = getHeaderOffset(payload.c_data(), payload.size(), reinterpret_cast<byte*>(&exifLongHeader), 4);
|
||||||
reinterpret_cast<byte*>(&exifLongHeader), 4);
|
|
||||||
|
|
||||||
if (pos == -1) {
|
if (pos == -1) {
|
||||||
pos = getHeaderOffset(payload.c_data(), static_cast<long>(payload.size()),
|
pos = getHeaderOffset(payload.c_data(), payload.size(), reinterpret_cast<byte*>(&exifLongHeader), 6);
|
||||||
reinterpret_cast<byte*>(&exifLongHeader), 6);
|
|
||||||
if (pos != -1) {
|
if (pos != -1) {
|
||||||
s_header = true;
|
s_header = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pos == -1) {
|
if (pos == -1) {
|
||||||
pos = getHeaderOffset(payload.c_data(), static_cast<long>(payload.size()),
|
pos = getHeaderOffset(payload.c_data(), payload.size(), reinterpret_cast<byte*>(&exifTiffLEHeader), 3);
|
||||||
reinterpret_cast<byte*>(&exifTiffLEHeader), 3);
|
|
||||||
if (pos != -1) {
|
if (pos != -1) {
|
||||||
le_header = true;
|
le_header = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pos == -1) {
|
if (pos == -1) {
|
||||||
pos = getHeaderOffset(payload.c_data(), static_cast<long>(payload.size()),
|
pos = getHeaderOffset(payload.c_data(), payload.size(), reinterpret_cast<byte*>(&exifTiffBEHeader), 4);
|
||||||
reinterpret_cast<byte*>(&exifTiffBEHeader), 4);
|
|
||||||
if (pos != -1) {
|
if (pos != -1) {
|
||||||
be_header = true;
|
be_header = true;
|
||||||
}
|
}
|
||||||
@ -835,14 +827,14 @@ void WebPImage::inject_VP8X(BasicIo& iIo, bool has_xmp, bool has_exif, bool has_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
long WebPImage::getHeaderOffset(const byte* data, long data_size, const byte* header, long header_size) {
|
long WebPImage::getHeaderOffset(const byte* data, size_t data_size, const byte* header, size_t header_size) {
|
||||||
if (data_size < header_size) {
|
if (data_size < header_size) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
long pos = -1;
|
long pos = -1;
|
||||||
for (long i = 0; i < data_size - header_size; i++) {
|
for (size_t i = 0; i < data_size - header_size; i++) {
|
||||||
if (memcmp(header, &data[i], header_size) == 0) {
|
if (memcmp(header, &data[i], header_size) == 0) {
|
||||||
pos = i;
|
pos = static_cast<long>(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -85,7 +85,7 @@ TEST(BmpImage, readMetadataReadsImageDimensionsWhenDataIsAvailable) {
|
|||||||
0x20, 0x03, 0x00, 0x00, // The bitmap height in pixels (unsigned 16 bit) off:22, size:4
|
0x20, 0x03, 0x00, 0x00, // The bitmap height in pixels (unsigned 16 bit) off:22, size:4
|
||||||
};
|
};
|
||||||
|
|
||||||
auto memIo = std::make_unique<MemIo>(header.data(), static_cast<long>(header.size()));
|
auto memIo = std::make_unique<MemIo>(header.data(), header.size());
|
||||||
BmpImage bmp(std::move(memIo));
|
BmpImage bmp(std::move(memIo));
|
||||||
ASSERT_NO_THROW(bmp.readMetadata());
|
ASSERT_NO_THROW(bmp.readMetadata());
|
||||||
ASSERT_EQ(1280, bmp.pixelWidth());
|
ASSERT_EQ(1280, bmp.pixelWidth());
|
||||||
@ -104,7 +104,7 @@ TEST(BmpImage, readMetadataThrowsWhenImageIsNotBMP) {
|
|||||||
0x20, 0x03, 0x00, 0x00, // The bitmap height in pixels (unsigned 16 bit) off:22, size:4
|
0x20, 0x03, 0x00, 0x00, // The bitmap height in pixels (unsigned 16 bit) off:22, size:4
|
||||||
};
|
};
|
||||||
|
|
||||||
auto memIo = std::make_unique<MemIo>(header.data(), static_cast<long>(header.size()));
|
auto memIo = std::make_unique<MemIo>(header.data(), header.size());
|
||||||
BmpImage bmp(std::move(memIo));
|
BmpImage bmp(std::move(memIo));
|
||||||
try {
|
try {
|
||||||
bmp.readMetadata();
|
bmp.readMetadata();
|
||||||
@ -117,7 +117,7 @@ TEST(BmpImage, readMetadataThrowsWhenImageIsNotBMP) {
|
|||||||
|
|
||||||
TEST(BmpImage, readMetadataThrowsWhenThereIsNotEnoughInfoToRead) {
|
TEST(BmpImage, readMetadataThrowsWhenThereIsNotEnoughInfoToRead) {
|
||||||
const std::array<unsigned char, 1> header{'B'};
|
const std::array<unsigned char, 1> header{'B'};
|
||||||
auto memIo = std::make_unique<MemIo>(header.data(), static_cast<long>(header.size()));
|
auto memIo = std::make_unique<MemIo>(header.data(), header.size());
|
||||||
BmpImage bmp(std::move(memIo));
|
BmpImage bmp(std::move(memIo));
|
||||||
try {
|
try {
|
||||||
bmp.readMetadata();
|
bmp.readMetadata();
|
||||||
@ -147,7 +147,7 @@ TEST(newBmpInstance, createsValidInstace) {
|
|||||||
0x00, 0x00, // Reserved
|
0x00, 0x00, // Reserved
|
||||||
0x00, 0x00, 0x00, 0x00 // Offset of the byte where the bitmap image data can be found
|
0x00, 0x00, 0x00, 0x00 // Offset of the byte where the bitmap image data can be found
|
||||||
};
|
};
|
||||||
auto memIo = std::make_unique<MemIo>(bitmapHeader.data(), static_cast<long>(bitmapHeader.size()));
|
auto memIo = std::make_unique<MemIo>(bitmapHeader.data(), bitmapHeader.size());
|
||||||
auto img = newBmpInstance(std::move(memIo), false);
|
auto img = newBmpInstance(std::move(memIo), false);
|
||||||
ASSERT_TRUE(img->good());
|
ASSERT_TRUE(img->good());
|
||||||
}
|
}
|
||||||
@ -166,7 +166,7 @@ TEST(isBmpType, withValidSignatureReturnsTrue) {
|
|||||||
0x00, 0x00, // Reserved
|
0x00, 0x00, // Reserved
|
||||||
0x00, 0x00, 0x00, 0x00 // Offset of the byte where the bitmap image data can be found
|
0x00, 0x00, 0x00, 0x00 // Offset of the byte where the bitmap image data can be found
|
||||||
};
|
};
|
||||||
MemIo memIo(bitmapHeader.data(), static_cast<long>(bitmapHeader.size()));
|
MemIo memIo(bitmapHeader.data(), bitmapHeader.size());
|
||||||
ASSERT_TRUE(isBmpType(memIo, false));
|
ASSERT_TRUE(isBmpType(memIo, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,6 +178,6 @@ TEST(isBmpType, withInvalidSignatureReturnsFalse) {
|
|||||||
0x00, 0x00, // Reserved
|
0x00, 0x00, // Reserved
|
||||||
0x00, 0x00, 0x00, 0x00 // Offset of the byte where the bitmap image data can be found
|
0x00, 0x00, 0x00, 0x00 // Offset of the byte where the bitmap image data can be found
|
||||||
};
|
};
|
||||||
MemIo memIo(bitmapHeader.data(), static_cast<long>(bitmapHeader.size()));
|
MemIo memIo(bitmapHeader.data(), bitmapHeader.size());
|
||||||
ASSERT_FALSE(isBmpType(memIo, false));
|
ASSERT_FALSE(isBmpType(memIo, false));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,7 @@ TEST(PngChunk, keyTxtChunkExtractsKeywordCorrectlyInPresenceOfNullChar) {
|
|||||||
0x20, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x74, 0x79,
|
0x20, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x74, 0x79,
|
||||||
0x70, 0x65, 0x20, 0x65, 0x78, 0x69, 0x66, 0x00, 0x00, 0x78};
|
0x70, 0x65, 0x20, 0x65, 0x78, 0x69, 0x66, 0x00, 0x00, 0x78};
|
||||||
|
|
||||||
DataBuf chunkBuf(data.data(), static_cast<long>(data.size()));
|
DataBuf chunkBuf(data.data(), data.size());
|
||||||
DataBuf key = Internal::PngChunk::keyTXTChunk(chunkBuf, true);
|
DataBuf key = Internal::PngChunk::keyTXTChunk(chunkBuf, true);
|
||||||
ASSERT_EQ(21, key.size());
|
ASSERT_EQ(21, key.size());
|
||||||
|
|
||||||
@ -31,13 +31,13 @@ TEST(PngChunk, keyTxtChunkThrowsExceptionWhenThereIsNoNullChar) {
|
|||||||
0x77, 0x20, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x20,
|
0x77, 0x20, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x20,
|
||||||
0x74, 0x79, 0x70, 0x65, 0x20, 0x65, 0x78, 0x69, 0x66, 0x78};
|
0x74, 0x79, 0x70, 0x65, 0x20, 0x65, 0x78, 0x69, 0x66, 0x78};
|
||||||
|
|
||||||
DataBuf chunkBuf(data.data(), static_cast<long>(data.size()));
|
DataBuf chunkBuf(data.data(), data.size());
|
||||||
ASSERT_THROW(Internal::PngChunk::keyTXTChunk(chunkBuf, true), Exiv2::Error);
|
ASSERT_THROW(Internal::PngChunk::keyTXTChunk(chunkBuf, true), Exiv2::Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(PngChunk, keyTxtChunkThrowsIfSizeIsNotEnough) {
|
TEST(PngChunk, keyTxtChunkThrowsIfSizeIsNotEnough) {
|
||||||
const std::array<std::uint8_t, 4> data{0x00, 0x00, 0x22, 0x41};
|
const std::array<std::uint8_t, 4> data{0x00, 0x00, 0x22, 0x41};
|
||||||
DataBuf chunkBuf(data.data(), static_cast<long>(data.size()));
|
DataBuf chunkBuf(data.data(), data.size());
|
||||||
ASSERT_THROW(Internal::PngChunk::keyTXTChunk(chunkBuf, true), Exiv2::Error);
|
ASSERT_THROW(Internal::PngChunk::keyTXTChunk(chunkBuf, true), Exiv2::Error);
|
||||||
|
|
||||||
DataBuf emptyChunk(data.data(), 0);
|
DataBuf emptyChunk(data.data(), 0);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user