27,145 changes: 27,145 additions & 0 deletions po/nl.po

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion releasenotes/CYGWIN/ReadMe.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CYGWIN Exiv2 v0.27.2-RC2 Bundle
CYGWIN Exiv2 v0.27.2 Bundle
-------------------------------

Structure of the bundle:
Expand All @@ -19,6 +19,7 @@ exiv2.png Exiv2 Logo
license.txt GPLv2.0 Software License
README.md Developer Manual
README-CONAN.md Developer Manual Appendix
README-SAMPLES.md Developer Sample Code Manual
releasenotes.txt Late breaking news

To run exiv2 from the bundle
Expand Down
7 changes: 4 additions & 3 deletions releasenotes/Darwin/ReadMe.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
MacOS-X (Darwin) Exiv2 v0.27.2-RC2 Bundle
MacOS-X (Darwin) Exiv2 v0.27.2 Bundle
-----------------------------------------

Structure of the bundle
-----------------------

bin/exiv2 exiv2 and sample applications
lib/libexiv2.0.27.2.2.dylib & libexiv2-xmp.a libraries
lib/libexiv2.0.27.2.dylib & libexiv2-xmp.a libraries
lib/pkgconfig/exiv2.pc pkg-config file
lib/cmake/exiv2 CMake support/consume files
include/exiv2/ include files
Expand All @@ -19,6 +19,7 @@ exiv2.png Exiv2 Logo
license.txt GPLv2.0 Software License
README.md Developer Manual
README-CONAN.md Developer Manual Appendix
README-SAMPLES.md Developer Sample Code Manual
releasenotes.txt Late breaking news

To run exiv2 from the bundle
Expand Down Expand Up @@ -48,4 +49,4 @@ $ g++ -std=c++98 samples/exifprint.cpp -o exifprint $(pkg-config exiv2 --libs --
$ ./exifprint

Method 3: Use the CMake support/consume files
See file: README.md Section: 2.6 "Consuming Exiv2 with CMake"
See file: README.md Section: 2.6 "Consuming Exiv2 with CMake"
5 changes: 3 additions & 2 deletions releasenotes/Linux/ReadMe.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Linux Exiv2 v0.27.2-RC2 Bundle
Linux Exiv2 v0.27.2-RC3 Bundle
------------------------------

Structure of the bundle:
------------------------

bin/exiv2 exiv2 and sample applications
lib/libexiv2.so.0.27.2.2 & libexiv2-xmp.a libraries
lib/libexiv2.so.0.27.2.3 & libexiv2-xmp.a libraries
lib/pkgconfig/exiv2.pc pkg-config file
lib/cmake/exiv2 CMake support/consume files
include/exiv2/ include files
Expand All @@ -19,6 +19,7 @@ license.txt GPLv2.0 Software License
releasenotes.txt Late breaking news
README.md Developer Manual
README-CONAN.md Developer Manual Appendix
README-SAMPLES.md Developer Sample Code Manual
exiv2.png Exiv2 Logo

To run exiv2 from the bundle
Expand Down
3 changes: 2 additions & 1 deletion releasenotes/MinGW/ReadMe.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MinGW/msys2 Exiv2 v0.27.2-RC2 Bundle
MinGW/msys2 Exiv2 v0.27.2 Bundle
------------------------------------

Structure of the bundle:
Expand All @@ -20,6 +20,7 @@ exiv2.png Exiv2 Logo
license.txt GPLv2.0 Software License
README.md Developer Manual
README-CONAN.md Developer Manual Appendix
README-SAMPLES.md Developer Sample Code Manual
releasenotes.txt Late breaking news

To run exiv2 from the bundle
Expand Down
5 changes: 3 additions & 2 deletions releasenotes/Unix/ReadMe.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Unix Exiv2 v0.27.2-RC2 Bundle (FreeBSD and NetBSD)
Unix Exiv2 v0.27.2 Bundle (FreeBSD and NetBSD)
--------------------------------------------------

Structure of the bundle:
------------------------

bin/exiv2 exiv2 and sample applications
lib/libexiv2.so.0.27.2.2 & libexiv2-xmp.a libraries
lib/libexiv2.so.0.27.2 & libexiv2-xmp.a libraries
lib/pkgconfig/exiv2.pc pkg-config file
lib/cmake/exiv2 CMake support/consume files
include/exiv2/ include files
Expand All @@ -19,6 +19,7 @@ license.txt GPLv2.0 Software License
releasenotes.txt Late breaking news
README.md Developer Manual
README-CONAN.md Developer Manual Appendix
README-SAMPLES.md Developer Sample Code Manual
exiv2.png Exiv2 Logo

To run exiv2 from the bundle
Expand Down
3 changes: 2 additions & 1 deletion releasenotes/msvc/ReadMe.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Visual Studio 2017 Release DLL v0.27.2-RC2 Bundle
Visual Studio 2017 Release DLL v0.27.2 Bundle
-------------------------------------------------

Structure of the bundle:
Expand All @@ -17,6 +17,7 @@ license.txt GPLv2.0 Software License
releasenotes.txt Late breaking news
README.md Developer Manual
README-CONAN.md Developer Manual Appendix
README-SAMPLES.md Developer Sample Code Manual
exiv2.png Exiv2 Logo

+----------------------------------------------------------------------------+
Expand Down
33 changes: 18 additions & 15 deletions releasenotes/releasenotes.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
Exiv2 v0.27.2.2 = Exiv2 v0.27.2 RC2
-----------------------------------
Exiv2 v0.27.2
-------------

Second Release Candidate for quarterly "dot" release of Exiv2 v0.27.2
Exiv2 v0.27 Second Dot Release

A huge thank you to Kevin for outstanding contributions to this release.
Thank You to Kevin for security contributions to this release.
Thank You to Ting-Wei for Unix contributions to this release.
Thank You to Dan and Luis for their solid efforts on Exiv2.
Thank You to Andreas S for representing Team Exiv2 at LGM 2019.
Contributors: Jens, Nehal, Phil, Toni
Contributors: Jens, Nehal, Phil, Toni, Paul

Headline Features of Exiv2 v0.27.2
----------------------------------

1) Bug and security fixes
2) Support for Unix (FreeBSD and NetBSD)
3) Support for Nikon/AutoFocus and Sony/FocusPosition Metadata
4) Documentation and man page revisions
5) Updated Catalan Localisation
6) Monitoring API changes for v0.27 dot releases
7) Using mergify to sync select PRs between 0.27-maintenance and 0.28

Issues fixed since v0.27.1
--------------------------
2) Support for Nikon/AutoFocus and Sony/FocusPosition Metadata
3) Documentation and man page revisions
4) Updated Catalan Localisation
5) Monitoring API changes for v0.27 dot releases
6) Using mergify to sync select PRs between 0.27-maintenance and 0.28
7) Preliminary Dutch Localisation
8) Preliminary Support for Unix (FreeBSD and NetBSD)
9) Better Build Bundle Dependency handling

Changes since 0.27.1
--------------------

https://github.com/Exiv2/exiv2/milestone/4?closed=1

Robin Mills
robin@clanmills.com
2019-06-29
2019-07-29

Headline Features of Exiv2 v0.27.1
----------------------------------
Expand Down
2 changes: 1 addition & 1 deletion samples/geotag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ int timeZoneAdjust()
struct tm local = *localtime(&now) ;
offset = local.tm_gmtoff ;

#if DEBUG
#if EXIV2_DEBUG_MESSAGES
struct tm utc = *gmtime(&now);
printf("utc : offset = %6d dst = %d time = %s", 0 ,utc .tm_isdst, asctime(&utc ));
printf("local: offset = %6d dst = %d time = %s", offset,local.tm_isdst, asctime(&local));
Expand Down
7 changes: 1 addition & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,9 @@ endif()

set_target_properties( exiv2lib_int PROPERTIES
POSITION_INDEPENDENT_CODE ON
COMPILE_DEFINITIONS exiv2lib_STATIC
COMPILE_DEFINITIONS exiv2lib_EXPORTS
)


target_include_directories(exiv2lib_int PRIVATE ${ZLIB_INCLUDE_DIR})
target_include_directories(exiv2lib PRIVATE ${ZLIB_INCLUDE_DIR})

Expand Down Expand Up @@ -197,10 +196,6 @@ if (WIN32)
endif()

if (NOT MSVC)
if ( UNIX AND NOT CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" )
target_link_libraries( exiv2lib PRIVATE ${CMAKE_DL_LIBS}) # -ldl = dynamic loader used by src/version.cpp
endif()

if ( CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" )
target_link_libraries( exiv2lib PRIVATE -lprocstat)
endif()
Expand Down
2 changes: 1 addition & 1 deletion src/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2070,7 +2070,7 @@ namespace {
int targetType,
bool preserve)
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "actions.cpp::metacopy" << " source = " << source << " target = " << tgt << std::endl;
#endif

Expand Down
35 changes: 25 additions & 10 deletions src/basicio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ namespace Exiv2 {
}
// #906. Mountain Lion 'sandbox' terminates the app when we call setxattr
#ifndef __APPLE__
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
EXV_DEBUG << "Copying xattr \"" << name << "\" with value size " << valueSize << "\n";
#endif
if (::setxattr(path_.c_str(), name, value, valueSize, 0, 0) != 0) {
Expand Down Expand Up @@ -337,19 +337,19 @@ namespace Exiv2 {
if (pfcn_GetFileInformationByHandle(hFd, &fi)) {
nlink = fi.nNumberOfLinks;
}
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
else EXV_DEBUG << "GetFileInformationByHandle failed\n";
#endif
}
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
else EXV_DEBUG << "GetProcAddress(hKernel, \"GetFileInformationByHandle\") failed\n";
#endif
}
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
else EXV_DEBUG << "GetModuleHandleA(\"kernel32.dll\") failed\n";
#endif
}
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
else EXV_DEBUG << "_get_osfhandle failed: INVALID_HANDLE_VALUE\n";
#endif

Expand Down Expand Up @@ -1291,15 +1291,23 @@ namespace Exiv2 {
#if defined(_MSC_VER)
int MemIo::seek( int64_t offset, Position pos )
{
uint64_t newIdx = 0;
int64_t newIdx = 0;

switch (pos) {
case BasicIo::cur: newIdx = p_->idx_ + offset; break;
case BasicIo::beg: newIdx = offset; break;
case BasicIo::end: newIdx = p_->size_ + offset; break;
}

p_->idx_ = static_cast<long>(newIdx); //not very sure about this. need more test!! - note by Shawn fly2xj@gmail.com //TODO
if (newIdx < 0)
return 1;

if (static_cast<size_t>(newIdx) > p_->size_) {
p_->eof_ = true;
return 1;
}

p_->idx_ = static_cast<long>(newIdx);
p_->eof_ = false;
return 0;
}
Expand All @@ -1314,7 +1322,14 @@ namespace Exiv2 {
case BasicIo::end: newIdx = p_->size_ + offset; break;
}

if (newIdx < 0) return 1;
if (newIdx < 0)
return 1;

if (newIdx > p_->size_) {
p_->eof_ = true;
return 1;
}

p_->idx_ = newIdx;
p_->eof_ = false;
return 0;
Expand Down Expand Up @@ -1730,7 +1745,7 @@ namespace Exiv2 {
p_->eof_ = false;
p_->idx_ = 0;
}
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "RemoteIo::close totalRead_ = " << p_->totalRead_ << std::endl;
#endif
if ( bigBlock_ ) {
Expand Down Expand Up @@ -1950,7 +1965,7 @@ namespace Exiv2 {
memcpy(bigBlock_+(block*blockSize),p,blockSize);
}
}
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "RemoteIo::mmap nRealData = " << nRealData << std::endl;
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion src/bmpimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace Exiv2

void BmpImage::readMetadata()
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Exiv2::BmpImage::readMetadata: Reading Windows bitmap file " << io_->path() << "\n";
#endif
if (io_->open() != 0) {
Expand Down
12 changes: 6 additions & 6 deletions src/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1374,7 +1374,7 @@ namespace {
{
// Naive byte-swapping, I'm sure this can be done more efficiently
if (str.size() & 1) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
EXV_DEBUG << "swapBytes: Size " << str.size() << " of input string is not even.\n";
#endif
return false;
Expand All @@ -1392,7 +1392,7 @@ namespace {
if (str.empty()) return true;
int len = MultiByteToWideChar(cp, 0, str.c_str(), (int)str.size(), 0, 0);
if (len == 0) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
EXV_DEBUG << "mb2wc: Failed to determine required size of output buffer.\n";
#endif
return false;
Expand All @@ -1401,7 +1401,7 @@ namespace {
out.resize(len * 2);
int ret = MultiByteToWideChar(cp, 0, str.c_str(), (int)str.size(), (LPWSTR)&out[0], len * 2);
if (ret == 0) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
EXV_DEBUG << "mb2wc: Failed to convert the input string to a wide character string.\n";
#endif
return false;
Expand All @@ -1414,14 +1414,14 @@ namespace {
{
if (str.empty()) return true;
if (str.size() & 1) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
EXV_DEBUG << "wc2mb: Size " << str.size() << " of input string is not even.\n";
#endif
return false;
}
int len = WideCharToMultiByte(cp, 0, (LPCWSTR)str.data(), (int)str.size() / 2, 0, 0, 0, 0);
if (len == 0) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
EXV_DEBUG << "wc2mb: Failed to determine required size of output buffer.\n";
#endif
return false;
Expand All @@ -1430,7 +1430,7 @@ namespace {
out.resize(len);
int ret = WideCharToMultiByte(cp, 0, (LPCWSTR)str.data(), (int)str.size() / 2, (LPSTR)&out[0], len, 0, 0);
if (ret == 0) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
EXV_DEBUG << "wc2mb: Failed to convert the input string to a multi byte string.\n";
#endif
return false;
Expand Down
6 changes: 3 additions & 3 deletions src/cr2image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace Exiv2 {

void Cr2Image::readMetadata()
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Reading CR2 file " << io_->path() << "\n";
#endif
if (io_->open() != 0) {
Expand All @@ -112,7 +112,7 @@ namespace Exiv2 {

void Cr2Image::writeMetadata()
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Writing CR2 file " << io_->path() << "\n";
#endif
ByteOrder bo = byteOrder();
Expand Down Expand Up @@ -174,7 +174,7 @@ namespace Exiv2 {
panaRawId
};
for (unsigned int i = 0; i < EXV_COUNTOF(filteredIfds); ++i) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Warning: Exif IFD " << filteredIfds[i] << " not encoded\n";
#endif
ed.erase(std::remove_if(ed.begin(),
Expand Down
6 changes: 3 additions & 3 deletions src/crwimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ namespace Exiv2 {

void CrwImage::readMetadata()
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Reading CRW file " << io_->path() << "\n";
#endif
if (io_->open() != 0) {
Expand All @@ -110,7 +110,7 @@ namespace Exiv2 {

void CrwImage::writeMetadata()
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Writing CRW file " << io_->path() << "\n";
#endif
// Read existing image
Expand Down Expand Up @@ -148,7 +148,7 @@ namespace Exiv2 {
// Parse the image, starting with a CIFF header component
CiffHeader::AutoPtr head(new CiffHeader);
head->read(pData, size);
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
head->print(std::cerr);
#endif
head->decode(*pCrwImage);
Expand Down
16 changes: 8 additions & 8 deletions src/crwimage_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ namespace Exiv2 {
offset_ = start + 2;
}
pData_ = pData + offset_;
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << " Entry for tag 0x"
<< std::hex << tagId() << " (0x" << tag()
<< "), " << std::dec << size_
Expand All @@ -265,11 +265,11 @@ namespace Exiv2 {
ByteOrder byteOrder)
{
CiffComponent::doRead(pData, size, start, byteOrder);
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Reading directory 0x" << std::hex << tag() << "\n";
#endif
readDirectory(pData + offset(), this->size(), byteOrder);
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "<---- 0x" << std::hex << tag() << "\n";
#endif
} // CiffDirectory::doRead
Expand All @@ -284,7 +284,7 @@ namespace Exiv2 {
if ( o > size-2 )
throw Error(kerCorruptedMetadata);
uint16_t count = getUShort(pData + o, byteOrder);
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Directory at offset " << std::dec << o
<<", " << count << " entries \n";
#endif
Expand Down Expand Up @@ -383,7 +383,7 @@ namespace Exiv2 {
uint32_t CiffComponent::writeValueData(Blob& blob, uint32_t offset)
{
if (dataLocation() == valueData) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << " Data for tag 0x" << std::hex << tagId()
<< ", " << std::dec << size_ << " Bytes\n";
#endif
Expand All @@ -403,7 +403,7 @@ namespace Exiv2 {
ByteOrder byteOrder,
uint32_t offset)
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Writing directory 0x" << std::hex << tag() << "---->\n";
#endif
// Ciff offsets are relative to the start of the directory
Expand Down Expand Up @@ -438,7 +438,7 @@ namespace Exiv2 {
setOffset(offset);
setSize(dirOffset);

#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Directory is at offset " << std::dec << dirStart
<< ", " << components_.size() << " entries\n"
<< "<---- 0x" << std::hex << tag() << "\n";
Expand All @@ -448,7 +448,7 @@ namespace Exiv2 {

void CiffComponent::writeDirEntry(Blob& blob, ByteOrder byteOrder) const
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << " Directory entry for tag 0x"
<< std::hex << tagId() << " (0x" << tag()
<< "), " << std::dec << size_
Expand Down
4 changes: 2 additions & 2 deletions src/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ namespace Exiv2 {
}

template<>
void BasicError<char>::setMsg()
void EXIV2API BasicError<char>::setMsg()
{
std::string msg = _(errMsg(code_));
std::string::size_type pos;
Expand Down Expand Up @@ -262,7 +262,7 @@ namespace Exiv2 {

#ifdef EXV_UNICODE_PATH
template<>
void BasicError<wchar_t>::setMsg()
void EXIV2API BasicError<wchar_t>::setMsg()
{
std::string s = _(errMsg(code_));
std::wstring wmsg(s.begin(), s.end());
Expand Down
6 changes: 3 additions & 3 deletions src/exif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ namespace Exiv2 {
for (unsigned int i = 0; i < EXV_COUNTOF(filteredIfd0Tags); ++i) {
ExifData::iterator pos = ed.findKey(ExifKey(filteredIfd0Tags[i]));
if (pos != ed.end()) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Warning: Exif tag " << pos->key() << " not encoded\n";
#endif
ed.erase(pos);
Expand All @@ -689,7 +689,7 @@ namespace Exiv2 {
ifd3Id
};
for (unsigned int i = 0; i < EXV_COUNTOF(filteredIfds); ++i) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Warning: Exif IFD " << filteredIfds[i] << " not encoded\n";
#endif
eraseIfd(ed, filteredIfds[i]);
Expand Down Expand Up @@ -816,7 +816,7 @@ namespace Exiv2 {
header.get(),
0);
append(blob, mio2.mmap(), (uint32_t) mio2.size());
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
if (wm == wmIntrusive) {
std::cerr << "SIZE OF EXIF DATA IS " << std::dec << mio2.size() << " BYTES\n";
}
Expand Down
2 changes: 1 addition & 1 deletion src/gifimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace Exiv2 {

void GifImage::readMetadata()
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Exiv2::GifImage::readMetadata: Reading GIF file " << io_->path() << "\n";
#endif
if (io_->open() != 0)
Expand Down
2 changes: 1 addition & 1 deletion src/iptc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ namespace Exiv2 {
uint32_t size
)
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "IptcParser::decode, size = " << size << "\n";
#endif
const byte* pRead = pData;
Expand Down
62 changes: 31 additions & 31 deletions src/jp2image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ namespace Exiv2
{
if (io_->open() == 0)
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Exiv2::Jp2Image:: Creating JPEG2000 image to memory" << std::endl;
#endif
IoCloser closer(*io_);
if (io_->write(Jp2Blank, sizeof(Jp2Blank)) != sizeof(Jp2Blank))
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Exiv2::Jp2Image:: Failed to create JPEG2000 image on memory" << std::endl;
#endif
}
Expand Down Expand Up @@ -199,7 +199,7 @@ namespace Exiv2

void Jp2Image::readMetadata()
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Exiv2::Jp2Image::readMetadata: Reading JPEG-2000 file " << io_->path() << std::endl;
#endif
if (io_->open() != 0)
Expand All @@ -225,7 +225,7 @@ namespace Exiv2
position = io_->tell();
box.length = getLong((byte*)&box.length, bigEndian);
box.type = getLong((byte*)&box.type, bigEndian);
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::readMetadata: "
<< "Position: " << position
<< " box type: " << toAscii(box.type)
Expand All @@ -244,7 +244,7 @@ namespace Exiv2
{
case kJp2BoxTypeJp2Header:
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::readMetadata: JP2Header box found" << std::endl;
#endif
long restore = io_->tell();
Expand All @@ -253,13 +253,13 @@ namespace Exiv2
{
subBox.length = getLong((byte*)&subBox.length, bigEndian);
subBox.type = getLong((byte*)&subBox.type, bigEndian);
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::readMetadata: "
<< "subBox = " << toAscii(subBox.type) << " length = " << subBox.length << std::endl;
#endif
if(subBox.type == kJp2BoxTypeColorHeader && subBox.length != 15)
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::readMetadata: "
<< "Color data found" << std::endl;
#endif
Expand All @@ -280,7 +280,7 @@ namespace Exiv2
}
DataBuf icc(iccLength);
::memcpy(icc.pData_,data.pData_+pad,icc.size_);
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
const char* iccPath = "/tmp/libexiv2_jp2.icc";
FILE* f = fopen(iccPath,"wb");
if ( f ) {
Expand All @@ -295,7 +295,7 @@ namespace Exiv2
if( subBox.type == kJp2BoxTypeImageHeader)
{
io_->read((byte*)&ihdr, sizeof(ihdr));
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::readMetadata: Ihdr data found" << std::endl;
#endif
ihdr.imageHeight = getLong((byte*)&ihdr.imageHeight, bigEndian);
Expand All @@ -316,7 +316,7 @@ namespace Exiv2

case kJp2BoxTypeUuid:
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::readMetadata: UUID box found" << std::endl;
#endif

Expand All @@ -330,7 +330,7 @@ namespace Exiv2

if(bIsExif)
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::readMetadata: Exif data found" << std::endl ;
#endif
rawData.alloc(box.length - (sizeof(box) + sizeof(uuid)));
Expand Down Expand Up @@ -362,7 +362,7 @@ namespace Exiv2
// If found it, store only these data at from this place.
if (pos >= 0 )
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::readMetadata: Exif header found at position " << pos << std::endl;
#endif
ByteOrder bo = TiffParser::decode(exifData(),
Expand All @@ -384,7 +384,7 @@ namespace Exiv2

if(bIsIPTC)
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::readMetadata: Iptc data found" << std::endl;
#endif
rawData.alloc(box.length - (sizeof(box) + sizeof(uuid)));
Expand All @@ -403,7 +403,7 @@ namespace Exiv2

if(bIsXMP)
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::readMetadata: Xmp data found" << std::endl;
#endif
rawData.alloc(box.length - (uint32_t)(sizeof(box) + sizeof(uuid)));
Expand Down Expand Up @@ -646,7 +646,7 @@ namespace Exiv2
if ( count < length ) {
subBox.length = getLong((byte*)&subBox.length, bigEndian);
subBox.type = getLong((byte*)&subBox.type , bigEndian);
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Jp2Image::encodeJp2Header subbox: "<< toAscii(subBox.type) << " length = " << subBox.length << std::endl;
#endif
count += subBox.length;
Expand Down Expand Up @@ -703,7 +703,7 @@ namespace Exiv2
if (!io_->isopen()) throw Error(kerInputDataReadFailed);
if (!outIo.isopen()) throw Error(kerImageWriteFailed);

#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::doWriteMetadata: Writing JPEG-2000 file " << io_->path() << std::endl;
std::cout << "Exiv2::Jp2Image::doWriteMetadata: tmp file created " << outIo.path() << std::endl;
#endif
Expand All @@ -729,7 +729,7 @@ namespace Exiv2

while(io_->tell() < (long) io_->size())
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::doWriteMetadata: Position: " << io_->tell() << " / " << io_->size() << std::endl;
#endif

Expand All @@ -745,14 +745,14 @@ namespace Exiv2
box.length = getLong(bheaderBuf.pData_, bigEndian);
box.type = getLong(bheaderBuf.pData_ + 4, bigEndian);

#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::doWriteMetadata: box type: " << toAscii(box.type)
<< " length: " << box.length << std::endl;
#endif

if (box.length == 0)
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::doWriteMetadata: Null Box size has been found. "
"This is the last box of file." << std::endl;
#endif
Expand All @@ -770,7 +770,7 @@ namespace Exiv2
bufRead = io_->read(boxBuf.pData_ + 8, box.length - 8); // Extract box data.
if (io_->error())
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::doWriteMetadata: Error reading source file" << std::endl;
#endif

Expand All @@ -779,7 +779,7 @@ namespace Exiv2

if (bufRead != (long)(box.length - 8))
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::doWriteMetadata: Cannot read source file data" << std::endl;
#endif
throw Error(kerInputDataReadFailed);
Expand All @@ -791,7 +791,7 @@ namespace Exiv2
{
DataBuf newBuf;
encodeJp2Header(boxBuf,newBuf);
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::doWriteMetadata: Write JP2Header box (length: " << box.length << ")" << std::endl;
#endif
if (outIo.write(newBuf.pData_, newBuf.size_) != newBuf.size_) throw Error(kerImageWriteFailed);
Expand All @@ -817,7 +817,7 @@ namespace Exiv2
memcpy(boxData.pData_ + 8, kJp2UuidExif, 16);
memcpy(boxData.pData_ + 8 + 16, rawExif.pData_, rawExif.size_);

#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::doWriteMetadata: Write box with Exif metadata (length: "
<< boxData.size_ << std::endl;
#endif
Expand All @@ -840,7 +840,7 @@ namespace Exiv2
memcpy(boxData.pData_ + 8, kJp2UuidIptc, 16);
memcpy(boxData.pData_ + 8 + 16, rawIptc.pData_, rawIptc.size_);

#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::doWriteMetadata: Write box with Iptc metadata (length: "
<< boxData.size_ << std::endl;
#endif
Expand Down Expand Up @@ -870,7 +870,7 @@ namespace Exiv2
memcpy(boxData.pData_ + 8, kJp2UuidXmp, 16);
memcpy(boxData.pData_ + 8 + 16, xmp.pData_, xmp.size_);

#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::doWriteMetadata: Write box with XMP metadata (length: "
<< boxData.size_ << ")" << std::endl;
#endif
Expand All @@ -884,25 +884,25 @@ namespace Exiv2
{
if(memcmp(boxBuf.pData_ + 8, kJp2UuidExif, 16) == 0)
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::doWriteMetadata: strip Exif Uuid box" << std::endl;
#endif
}
else if(memcmp(boxBuf.pData_ + 8, kJp2UuidIptc, 16) == 0)
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::doWriteMetadata: strip Iptc Uuid box" << std::endl;
#endif
}
else if(memcmp(boxBuf.pData_ + 8, kJp2UuidXmp, 16) == 0)
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::doWriteMetadata: strip Xmp Uuid box" << std::endl;
#endif
}
else
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::doWriteMetadata: write Uuid box (length: " << box.length << ")" << std::endl;
#endif
if (outIo.write(boxBuf.pData_, boxBuf.size_) != boxBuf.size_) throw Error(kerImageWriteFailed);
Expand All @@ -912,7 +912,7 @@ namespace Exiv2

default:
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::doWriteMetadata: write box (length: " << box.length << ")" << std::endl;
#endif
if (outIo.write(boxBuf.pData_, boxBuf.size_) != boxBuf.size_) throw Error(kerImageWriteFailed);
Expand All @@ -922,7 +922,7 @@ namespace Exiv2
}
}

#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::Jp2Image::doWriteMetadata: EOF" << std::endl;
#endif

Expand Down
36 changes: 18 additions & 18 deletions src/jpgimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ namespace Exiv2 {
assert(sizeData);
// Used for error checking
long position = 0;
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Photoshop::locateIrb: ";
#endif
// Data should follow Photoshop format, if not exit
Expand All @@ -160,15 +160,15 @@ namespace Exiv2 {
position += 4;
uint16_t type = getUShort(pPsData + position, bigEndian);
position += 2;
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "0x" << std::hex << type << std::dec << " ";
#endif
// Pascal string is padded to have an even size (including size byte)
byte psSize = pPsData[position] + 1;
psSize += (psSize & 1);
position += psSize;
if (position + 4 > sizePsData) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Warning: "
<< "Invalid or extended Photoshop IRB\n";
#endif
Expand All @@ -177,22 +177,22 @@ namespace Exiv2 {
uint32_t dataSize = getULong(pPsData + position, bigEndian);
position += 4;
if (dataSize > static_cast<uint32_t>(sizePsData - position)) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Warning: "
<< "Invalid Photoshop IRB data size "
<< dataSize << " or extended Photoshop IRB\n";
#endif
return -2;
}
#ifndef DEBUG
#ifndef EXIV2_DEBUG_MESSAGES
if ( (dataSize & 1)
&& position + dataSize == static_cast<uint32_t>(sizePsData)) {
std::cerr << "Warning: "
<< "Photoshop IRB data is not padded to even size\n";
}
#endif
if (type == psTag) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "ok\n";
#endif
*sizeData = dataSize;
Expand All @@ -203,11 +203,11 @@ namespace Exiv2 {
// Data size is also padded to be even
position += dataSize + (dataSize & 1);
}
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "pPsData doesn't start with '8BIM'\n";
#endif
if (position < sizePsData) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Warning: "
<< "Invalid or extended Photoshop IRB\n";
#endif
Expand Down Expand Up @@ -241,7 +241,7 @@ namespace Exiv2 {
const IptcData& iptcData)
{
if (sizePsData > 0) assert(pPsData);
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "IRB block at the beginning of Photoshop::setIptcIrb\n";
if (sizePsData == 0) std::cerr << " None.\n";
else hexdump(std::cerr, pPsData, sizePsData);
Expand Down Expand Up @@ -293,7 +293,7 @@ namespace Exiv2 {
}
// Data is rounded to be even
if (psBlob.size() > 0) rc = DataBuf(&psBlob[0], static_cast<long>(psBlob.size()));
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "IRB block at the end of Photoshop::setIptcIrb\n";
if (rc.size_ == 0) std::cerr << " None.\n";
else hexdump(std::cerr, rc.pData_, rc.size_);
Expand Down Expand Up @@ -427,7 +427,7 @@ namespace Exiv2 {
DataBuf psData(size - 16);
io_->read(psData.pData_, psData.size_);
if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData);
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Found app13 segment, size = " << size << "\n";
//hexdump(std::cerr, psData.pData_, psData.size_);
#endif
Expand Down Expand Up @@ -476,7 +476,7 @@ namespace Exiv2 {
// chunk/chunks are a single byte
// Spec 7.2 Profile bytes 0-3 size
uint32_t s = getULong(buf.pData_ + (2+14) , bigEndian);
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Found ICC Profile chunk " << chunk
<< " of " << chunks
<< (chunk==1 ? " size: " : "" ) << (chunk==1 ? s : 0)
Expand Down Expand Up @@ -544,7 +544,7 @@ namespace Exiv2 {
while ( pCur < pEnd
&& 0 == Photoshop::locateIptcIrb(pCur, static_cast<long>(pEnd - pCur),
&record, &sizeHdr, &sizeIptc)) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Found IPTC IRB, size = " << sizeIptc << "\n";
#endif
if (sizeIptc) {
Expand Down Expand Up @@ -706,7 +706,7 @@ namespace Exiv2 {
DataBuf icc(size - (14 + 2));
io_->read(icc.pData_, icc.size_);
out.write(reinterpret_cast<const char*>(icc.pData_), icc.size_);
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "iccProfile size = " << icc.size_ << std::endl;
#endif
bufRead = size;
Expand Down Expand Up @@ -835,7 +835,7 @@ namespace Exiv2 {
}
}
if (option == kpsIptcErase && iptcDataSegs.size()) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "iptc data blocks: " << iptcDataSegs.size() << std::endl;
uint32_t toggle = 0;
for (Uint32Vector_i i = iptcDataSegs.begin(); i != iptcDataSegs.end(); i++) {
Expand All @@ -860,7 +860,7 @@ namespace Exiv2 {
++it;
}
pos[count + 1] = io_->size() - pos[count];
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
for (uint64_t i = 0; i < count + 2; i++)
std::cout << pos[i] << " ";
std::cout << std::endl;
Expand All @@ -880,7 +880,7 @@ namespace Exiv2 {
start = 0; // read the file 2 byte SOI
long length = (long)(pos[2 * i + 1] - start);
if (length) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << start << ":" << length << std::endl;
#endif
io_->seek(start, BasicIo::beg);
Expand Down Expand Up @@ -999,7 +999,7 @@ namespace Exiv2 {
if (io_->seek(size - bufRead, BasicIo::cur))
throw Error(kerNoImageInInputData);
} else if (!foundCompletePsData && marker == app13_ && memcmp(buf.pData_ + 2, Photoshop::ps3Id_, 14) == 0) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Found APP13 Photoshop PS3 segment\n";
#endif
if (size < 16)
Expand Down
24 changes: 16 additions & 8 deletions src/mrwimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "image.hpp"
#include "basicio.hpp"
#include "error.hpp"
#include "enforce.hpp"
#include "futils.hpp"

// + standard includes
Expand Down Expand Up @@ -92,7 +93,7 @@ namespace Exiv2 {

void MrwImage::readMetadata()
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Reading MRW file " << io_->path() << "\n";
#endif
if (io_->open() != 0) {
Expand All @@ -114,26 +115,33 @@ namespace Exiv2 {
uint32_t const end = getULong(tmp + 4, bigEndian);

pos += len;
if (pos > end) throw Error(kerFailedToReadImageData);
enforce(pos <= end, kerFailedToReadImageData);
io_->read(tmp, len);
if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData);

while (memcmp(tmp + 1, "TTW", 3) != 0) {
uint32_t const siz = getULong(tmp + 4, bigEndian);
enforce(siz <= end - pos, kerFailedToReadImageData);
pos += siz;
if (pos > end) throw Error(kerFailedToReadImageData);
io_->seek(siz, BasicIo::cur);
if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData);
enforce(!io_->error() && !io_->eof(), kerFailedToReadImageData);

enforce(len <= end - pos, kerFailedToReadImageData);
pos += len;
if (pos > end) throw Error(kerFailedToReadImageData);
io_->read(tmp, len);
if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData);
enforce(!io_->error() && !io_->eof(), kerFailedToReadImageData);
}

DataBuf buf(getULong(tmp + 4, bigEndian));
const uint32_t siz = getULong(tmp + 4, bigEndian);
// First do an approximate bounds check of siz, so that we don't
// get DOS-ed by a 4GB allocation on the next line. If siz is
// greater than io_->size() then it is definitely invalid. But the
// exact bounds checking is done by the call to io_->read, which
// will fail if there are fewer than siz bytes left to read.
enforce(siz <= io_->size(), kerFailedToReadImageData);
DataBuf buf(siz);
io_->read(buf.pData_, buf.size_);
if (io_->error() || io_->eof()) throw Error(kerFailedToReadImageData);
enforce(!io_->error() && !io_->eof(), kerFailedToReadImageData);

ByteOrder bo = TiffParser::decode(exifData_,
iptcData_,
Expand Down
6 changes: 3 additions & 3 deletions src/orfimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ namespace Exiv2 {

void OrfImage::readMetadata()
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Reading ORF file " << io_->path() << "\n";
#endif
if (io_->open() != 0) {
Expand All @@ -124,7 +124,7 @@ namespace Exiv2 {

void OrfImage::writeMetadata()
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Writing ORF file " << io_->path() << "\n";
#endif
ByteOrder bo = byteOrder();
Expand Down Expand Up @@ -186,7 +186,7 @@ namespace Exiv2 {
panaRawId
};
for (unsigned int i = 0; i < EXV_COUNTOF(filteredIfds); ++i) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Warning: Exif IFD " << filteredIfds[i] << " not encoded\n";
#endif
ed.erase(std::remove_if(ed.begin(),
Expand Down
18 changes: 9 additions & 9 deletions src/pgfimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ namespace Exiv2 {
{
if (io_->open() == 0)
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Exiv2::PgfImage:: Creating PGF image to memory\n";
#endif
IoCloser closer(*io_);
if (io_->write(pgfBlank, sizeof(pgfBlank)) != sizeof(pgfBlank))
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Exiv2::PgfImage:: Failed to create PGF image on memory\n";
#endif
}
Expand All @@ -106,7 +106,7 @@ namespace Exiv2 {

void PgfImage::readMetadata()
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Exiv2::PgfImage::readMetadata: Reading PGF file " << io_->path() << "\n";
#endif
if (io_->open() != 0)
Expand Down Expand Up @@ -136,7 +136,7 @@ namespace Exiv2 {
#endif
long size = static_cast<long>(headerSize) + 8 - io_->tell();

#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PgfImage::readMetadata: Found Image data (" << size << " bytes)\n";
#endif

Expand Down Expand Up @@ -178,7 +178,7 @@ namespace Exiv2 {
if (!io_->isopen()) throw Error(kerInputDataReadFailed);
if (!outIo.isopen()) throw Error(kerImageWriteFailed);

#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PgfImage::doWriteMetadata: Writing PGF file " << io_->path() << "\n";
std::cout << "Exiv2::PgfImage::doWriteMetadata: tmp file created " << outIo.path() << "\n";
#endif
Expand Down Expand Up @@ -207,7 +207,7 @@ namespace Exiv2 {
long imgSize = (long) img->io().size();
DataBuf imgBuf = img->io().read(imgSize);

#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PgfImage::doWriteMetadata: Creating image to host metadata (" << imgSize << " bytes)\n";
#endif

Expand All @@ -226,7 +226,7 @@ namespace Exiv2 {
byteSwap_(buffer,0,bSwap_);
if (outIo.write(buffer.pData_, 4) != 4) throw Error(kerImageWriteFailed);

#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PgfImage: new PGF header size : " << newHeaderSize << " bytes\n";

printf("%x\n", buffer.pData_[0]);
Expand Down Expand Up @@ -261,7 +261,7 @@ namespace Exiv2 {
if (b < 0x36) // 0x36 = '6'.
{
// Not right Magick version.
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PgfImage::readMetadata: wrong Magick number\n";
#endif
}
Expand All @@ -279,7 +279,7 @@ namespace Exiv2 {
int headerSize = (int) byteSwap_(buffer,0,bSwap_);
if (headerSize <= 0 ) throw Error(kerNoImageInInputData);

#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PgfImage: PGF header size : " << headerSize << " bytes\n";
#endif

Expand Down
24 changes: 12 additions & 12 deletions src/pngchunk_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ namespace Exiv2 {
DataBuf key = keyTXTChunk(data);
DataBuf arr = parseTXTChunk(data, key.size_, type);

#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PngChunk::decodeTXTChunk: TXT chunk data: "
<< std::string((const char*)arr.pData_, arr.size_) << std::endl;
#endif
Expand All @@ -96,7 +96,7 @@ namespace Exiv2 {
{
DataBuf key = keyTXTChunk(data);

#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PngChunk::decodeTXTChunk: TXT chunk key: "
<< std::string((const char*)key.pData_, key.size_) << std::endl;
#endif
Expand Down Expand Up @@ -143,7 +143,7 @@ namespace Exiv2 {
if ( *compressionMethod != 0x00 )
{
// then it isn't zlib compressed and we are sunk
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Exiv2::PngChunk::parseTXTChunk: Non-standard zTXt compression method.\n";
#endif
throw Error(kerFailedToReadImageData);
Expand Down Expand Up @@ -208,15 +208,15 @@ namespace Exiv2 {

if (compressionFlag == 0x00) {
// then it's an uncompressed iTXt chunk
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PngChunk::parseTXTChunk: We found an uncompressed iTXt field\n";
#endif

arr.alloc(textsize);
arr = DataBuf(text, textsize);
} else if (compressionFlag == 0x01 && compressionMethod == 0x00) {
// then it's a zlib compressed iTXt chunk
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PngChunk::parseTXTChunk: We found a zlib compressed iTXt field\n";
#endif

Expand All @@ -225,7 +225,7 @@ namespace Exiv2 {
}
} else {
// then it isn't zlib compressed and we are sunk
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Exiv2::PngChunk::parseTXTChunk: Non-standard iTXt compression method.\n";
#endif
throw Error(kerFailedToReadImageData);
Expand Down Expand Up @@ -278,7 +278,7 @@ namespace Exiv2 {

if (pos !=-1)
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PngChunk::parseChunkContent: Exif header found at position " << pos << "\n";
#endif
pos = pos + sizeof(exifHeader);
Expand Down Expand Up @@ -320,7 +320,7 @@ namespace Exiv2 {
&sizeHdr,
&sizeIptc)) {
if (sizeIptc) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Found IPTC IRB, size = " << sizeIptc << "\n";
#endif
append(iptcBlob, record + sizeHdr, sizeIptc);
Expand Down Expand Up @@ -510,7 +510,7 @@ namespace Exiv2 {
break;
case Z_BUF_ERROR:
// The compressed array needs to be larger
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PngChunk::parsePngChunk: doubling size for compression.\n";
#endif
compressedLen *= 2;
Expand Down Expand Up @@ -680,14 +680,14 @@ namespace Exiv2 {
// Allocate space
if (length == 0)
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Exiv2::PngChunk::readRawProfile: Unable To Copy Raw Profile: invalid profile length\n";
#endif
}
info.alloc(length);
if (info.size_ != length)
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Exiv2::PngChunk::readRawProfile: Unable To Copy Raw Profile: cannot allocate memory\n";
#endif
return DataBuf();
Expand All @@ -705,7 +705,7 @@ namespace Exiv2 {
{
if (*sp == '\0')
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Exiv2::PngChunk::readRawProfile: Unable To Copy Raw Profile: ran out of data\n";
#endif
return DataBuf();
Expand Down
31 changes: 15 additions & 16 deletions src/pngimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ namespace
{
inline bool compare(const char* str, const Exiv2::DataBuf& buf, size_t length)
{
// str & length should compile time constants => only running this in DEBUG mode is ok
assert(strlen(str) <= length);
return memcmp(str, buf.pData_, std::min(static_cast<long>(length), buf.size_)) == 0;
}
Expand All @@ -80,13 +79,13 @@ namespace Exiv2 {
{
if (io_->open() == 0)
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Exiv2::PngImage:: Creating PNG image to memory\n";
#endif
IoCloser closer(*io_);
if (io_->write(pngBlank, sizeof(pngBlank)) != sizeof(pngBlank))
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Exiv2::PngImage:: Failed to create PNG image on memory\n";
#endif
}
Expand Down Expand Up @@ -350,7 +349,7 @@ namespace Exiv2 {

if ( bExif || bIptc ) {
DataBuf parsedBuf = PngChunk::readRawProfile(dataBuf,tEXt);
#if DEBUG
#if EXIV2_DEBUG_MESSAGES
std::cerr << Exiv2::Internal::binaryToString(parsedBuf.pData_, parsedBuf.size_>50?50:parsedBuf.size_,0) << std::endl;
#endif
if ( parsedBuf.size_ ) {
Expand Down Expand Up @@ -397,7 +396,7 @@ namespace Exiv2 {

void readChunk(DataBuf& buffer, BasicIo& io)
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PngImage::readMetadata: Position: " << io.tell() << std::endl;
#endif
long bufRead = io.read(buffer.pData_, buffer.size_);
Expand All @@ -411,7 +410,7 @@ namespace Exiv2 {

void PngImage::readMetadata()
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Exiv2::PngImage::readMetadata: Reading PNG file " << io_->path() << std::endl;
#endif
if (io_->open() != 0)
Expand Down Expand Up @@ -442,7 +441,7 @@ namespace Exiv2 {
}

std::string chunkType(reinterpret_cast<char *>(cheaderBuf.pData_) + 4, 4);
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PngImage::readMetadata: chunk type: " << chunkType
<< " length: " << chunkLength << std::endl;
#endif
Expand Down Expand Up @@ -477,7 +476,7 @@ namespace Exiv2 {
enforce(iccOffset <= chunkLength, Exiv2::kerCorruptedMetadata);

zlibToDataBuf(chunkData.pData_ + iccOffset, chunkLength - iccOffset, iccProfile_);
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PngImage::readMetadata: profile name: " << profileName_ << std::endl;
std::cout << "Exiv2::PngImage::readMetadata: iccProfile.size_ (uncompressed) : "
<< iccProfile_.size_ << std::endl;
Expand All @@ -491,7 +490,7 @@ namespace Exiv2 {


// Move to the next chunk: chunk data size + 4 CRC bytes.
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PngImage::readMetadata: Seek to offset: " << chunkLength + 4 << std::endl;
#endif
io_->seek(chunkLength + 4 , BasicIo::cur);
Expand Down Expand Up @@ -522,7 +521,7 @@ namespace Exiv2 {
if (!io_->isopen()) throw Error(kerInputDataReadFailed);
if (!outIo.isopen()) throw Error(kerImageWriteFailed);

#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PngImage::doWriteMetadata: Writing PNG file " << io_->path() << "\n";
std::cout << "Exiv2::PngImage::doWriteMetadata: tmp file created " << outIo.path() << "\n";
#endif
Expand Down Expand Up @@ -565,15 +564,15 @@ namespace Exiv2 {
if (!memcmp(cheaderBuf.pData_ + 4, "IEND", 4))
{
// Last chunk found: we write it and done.
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PngImage::doWriteMetadata: Write IEND chunk (length: " << dataOffset << ")\n";
#endif
if (outIo.write(chunkBuf.pData_, chunkBuf.size_) != chunkBuf.size_) throw Error(kerImageWriteFailed);
return;
}
else if (!memcmp(cheaderBuf.pData_ + 4, "IHDR", 4))
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PngImage::doWriteMetadata: Write IHDR chunk (length: " << dataOffset << ")\n";
#endif
if (outIo.write(chunkBuf.pData_, chunkBuf.size_) != chunkBuf.size_) throw Error(kerImageWriteFailed);
Expand Down Expand Up @@ -651,7 +650,7 @@ namespace Exiv2 {
){
throw Error(kerImageWriteFailed);
}
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PngImage::doWriteMetadata: build iCCP"
<< " chunk (length: " << compressed.size_ + chunkLength << ")" << std::endl;
#endif
Expand Down Expand Up @@ -688,14 +687,14 @@ namespace Exiv2 {
compare("ICC", key, 3) ||
compare("Description", key, 11))
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PngImage::doWriteMetadata: strip " << szChunk
<< " chunk (length: " << dataOffset << ")" << std::endl;
#endif
}
else
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PngImage::doWriteMetadata: write " << szChunk
<< " chunk (length: " << dataOffset << ")" << std::endl;
#endif
Expand All @@ -705,7 +704,7 @@ namespace Exiv2 {
else
{
// Write all others chunk as well.
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PngImage::doWriteMetadata: copy " << szChunk
<< " chunk (length: " << dataOffset << ")" << std::endl;
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2618,7 +2618,7 @@ namespace Exiv2 {
prefix = property.substr(0, i);
property = property.substr(i+1);
}
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Nested key: " << key.key() << ", prefix: " << prefix
<< ", property: " << property << "\n";
#endif
Expand Down
22 changes: 11 additions & 11 deletions src/psdimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ namespace Exiv2 {

void PsdImage::readMetadata()
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Exiv2::PsdImage::readMetadata: Reading Photoshop file " << io_->path() << "\n";
#endif
if (io_->open() != 0)
Expand Down Expand Up @@ -232,7 +232,7 @@ namespace Exiv2 {
uint32_t resourceSize = getULong(buf, bigEndian);
uint32_t curOffset = io_->tell();

#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << std::hex << "resourceId: " << resourceId << std::dec << " length: " << resourceSize << std::hex << "\n";
#endif

Expand Down Expand Up @@ -370,7 +370,7 @@ namespace Exiv2 {
if (!io_->isopen()) throw Error(kerInputDataReadFailed);
if (!outIo.isopen()) throw Error(kerImageWriteFailed);

#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Exiv2::PsdImage::doWriteMetadata: Writing PSD file " << io_->path() << "\n";
std::cout << "Exiv2::PsdImage::doWriteMetadata: tmp file created " << outIo.path() << "\n";
#endif
Expand Down Expand Up @@ -401,7 +401,7 @@ namespace Exiv2 {
// Write colorDataLength
ul2Data(buf, colorDataLength, bigEndian);
if (outIo.write(buf, 4) != 4) throw Error(kerImageWriteFailed);
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << std::dec << "colorDataLength: " << colorDataLength << "\n";
#endif
// Copy colorData
Expand All @@ -428,7 +428,7 @@ namespace Exiv2 {
ul2Data(buf, oldResLength, bigEndian);
if (outIo.write(buf, 4) != 4) throw Error(kerImageWriteFailed);

#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << std::dec << "oldResLength: " << oldResLength << "\n";
#endif

Expand Down Expand Up @@ -491,7 +491,7 @@ namespace Exiv2 {
if ( resourceId != kPhotoshopResourceID_IPTC_NAA
&& resourceId != kPhotoshopResourceID_ExifInfo
&& resourceId != kPhotoshopResourceID_XMPPacket) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << std::hex << "copy : resourceType: " << resourceType << "\n";
std::cerr << std::hex << "copy : resourceId: " << resourceId << "\n";
std::cerr << std::dec;
Expand Down Expand Up @@ -560,7 +560,7 @@ namespace Exiv2 {
if (outIo.error()) throw Error(kerImageWriteFailed);

// Update length of resources
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "newResLength: " << newResLength << "\n";
#endif
outIo.seek(resLenOffset, BasicIo::beg);
Expand All @@ -577,7 +577,7 @@ namespace Exiv2 {
if (iptcData.count() > 0) {
DataBuf rawIptc = IptcParser::encode(iptcData);
if (rawIptc.size_ > 0) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << std::hex << "write: resourceId: " << kPhotoshopResourceID_IPTC_NAA << "\n";
std::cerr << std::dec << "Writing IPTC_NAA: size: " << rawIptc.size_ << "\n";
#endif
Expand Down Expand Up @@ -617,7 +617,7 @@ namespace Exiv2 {
ExifParser::encode(blob, bo, exifData);

if (blob.size() > 0) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << std::hex << "write: resourceId: " << kPhotoshopResourceID_ExifInfo << "\n";
std::cerr << std::dec << "Writing ExifInfo: size: " << blob.size() << "\n";
#endif
Expand Down Expand Up @@ -648,7 +648,7 @@ namespace Exiv2 {
uint32_t resLength = 0;
byte buf[8];

#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "writeXmpFromPacket(): " << writeXmpFromPacket() << "\n";
#endif
// writeXmpFromPacket(true);
Expand All @@ -661,7 +661,7 @@ namespace Exiv2 {
}

if (xmpPacket.size() > 0) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << std::hex << "write: resourceId: " << kPhotoshopResourceID_XMPPacket << "\n";
std::cerr << std::dec << "Writing XMPPacket: size: " << xmpPacket.size() << "\n";
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/rafimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ namespace Exiv2 {

void RafImage::readMetadata()
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Reading RAF file " << io_->path() << "\n";
#endif
if (io_->open() != 0) throw Error(kerDataSourceOpenFailed, io_->path(), strError());
Expand Down
8 changes: 4 additions & 4 deletions src/rw2image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include "futils.hpp"

// + standard includes
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
# include <iostream>
#endif

Expand Down Expand Up @@ -112,7 +112,7 @@ namespace Exiv2 {

void Rw2Image::readMetadata()
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Reading RW2 file " << io_->path() << "\n";
#endif
if (io_->open() != 0) {
Expand Down Expand Up @@ -160,7 +160,7 @@ namespace Exiv2 {
if (pos->ifdId() == panaRawId) continue;
ExifData::iterator dup = prevData.findKey(ExifKey(pos->key()));
if (dup != prevData.end()) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Filtering duplicate tag " << pos->key()
<< " (values '" << pos->value()
<< "' and '" << dup->value() << "')\n";
Expand Down Expand Up @@ -203,7 +203,7 @@ namespace Exiv2 {
for (unsigned int i = 0; i < EXV_COUNTOF(filteredTags); ++i) {
ExifData::iterator pos = prevData.findKey(ExifKey(filteredTags[i]));
if (pos != prevData.end()) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Exif tag " << pos->key() << " removed\n";
#endif
prevData.erase(pos);
Expand Down
2 changes: 1 addition & 1 deletion src/tgaimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace Exiv2 {

void TgaImage::readMetadata()
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Exiv2::TgaImage::readMetadata: Reading TARGA file " << io_->path() << "\n";
#endif
if (io_->open() != 0)
Expand Down
10 changes: 5 additions & 5 deletions src/tiffcomposite_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ namespace Exiv2 {

// Remember the offset of the CR2 RAW IFD
if (group() == ifd3Id) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Directory " << groupName(group()) << " offset is 0x"
<< std::setw(8) << std::setfill('0') << std::hex << offset << std::dec
<< "\n";
Expand Down Expand Up @@ -1314,7 +1314,7 @@ namespace Exiv2 {
uint32_t o2 = imageIdx;
// For makernotes, write TIFF image data to the data area
if (group() > mnId) o2 = offset + dataIdx;
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "TiffImageEntry, Directory " << groupName(group())
<< ", entry 0x" << std::setw(4)
<< std::setfill('0') << std::hex << tag() << std::dec
Expand Down Expand Up @@ -1613,7 +1613,7 @@ namespace Exiv2 {

uint32_t len = pValue()->sizeDataArea();
if (len > 0) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "TiffImageEntry, Directory " << groupName(group())
<< ", entry 0x" << std::setw(4)
<< std::setfill('0') << std::hex << tag() << std::dec
Expand All @@ -1626,7 +1626,7 @@ namespace Exiv2 {
len += align;
}
else {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "TiffImageEntry, Directory " << groupName(group())
<< ", entry 0x" << std::setw(4)
<< std::setfill('0') << std::hex << tag() << std::dec
Expand All @@ -1641,7 +1641,7 @@ namespace Exiv2 {
len += align;
}
}
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << ", len = " << len << " bytes\n";
#endif
return len;
Expand Down
6 changes: 3 additions & 3 deletions src/tiffimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ namespace Exiv2 {

void TiffImage::readMetadata()
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Reading TIFF file " << io_->path() << "\n";
#endif
if (io_->open() != 0) {
Expand Down Expand Up @@ -207,7 +207,7 @@ namespace Exiv2 {

void TiffImage::writeMetadata()
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Writing TIFF file " << io_->path() << "\n";
#endif
ByteOrder bo = byteOrder();
Expand Down Expand Up @@ -283,7 +283,7 @@ namespace Exiv2 {
panaRawId
};
for (unsigned int i = 0; i < EXV_COUNTOF(filteredIfds); ++i) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Warning: Exif IFD " << filteredIfds[i] << " not encoded\n";
#endif
ed.erase(std::remove_if(ed.begin(),
Expand Down
14 changes: 7 additions & 7 deletions src/tiffimage_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1562,7 +1562,7 @@ namespace Exiv2 {
if (ts && ts->newTiffCompFct_) {
tc = ts->newTiffCompFct_(tag, group);
}
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
else {
if (!ts) {
std::cerr << "Warning: No TIFF structure entry found for ";
Expand Down Expand Up @@ -1944,13 +1944,13 @@ namespace Exiv2 {

// If tag, group is one of the image tags listed above -> bingo!
if (find(tiffImageTags, TiffImgTagStruct::Key(tag, group))) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
ExifKey key(tag, groupName(group));
std::cerr << "Image tag: " << key << " (3)\n";
#endif
return true;
}
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Not an image tag: " << tag << " (4)\n";
#endif
return false;
Expand All @@ -1971,20 +1971,20 @@ namespace Exiv2 {
const PrimaryGroups* pPrimaryGroups) const
{
if (!hasImageTags_) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "No image tags in this image\n";
#endif
return false;
}
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
ExifKey key(tag, groupName(group));
#endif
// If there are primary groups and none matches group, we're done
if ( pPrimaryGroups != 0
&& !pPrimaryGroups->empty()
&& std::find(pPrimaryGroups->begin(), pPrimaryGroups->end(), group)
== pPrimaryGroups->end()) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Not an image tag: " << key << " (1)\n";
#endif
return false;
Expand All @@ -1994,7 +1994,7 @@ namespace Exiv2 {
if ( pPrimaryGroups != 0
&& !pPrimaryGroups->empty()
&& group != ifd0Id) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
ExifKey key(tag, groupName(group));
std::cerr << "Image tag: " << key << " (2)\n";
#endif
Expand Down
34 changes: 17 additions & 17 deletions src/tiffvisitor_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ namespace Exiv2 {
TiffPath tiffPath;
TiffCreator::getPath(tiffPath, object->tag(), object->group(), root_);
pRoot_->addPath(object->tag(), tiffPath, pRoot_, clone);
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
ExifKey key(object->tag(), groupName(object->group()));
std::cerr << "Copied " << key << "\n";
#endif
Expand Down Expand Up @@ -698,7 +698,7 @@ namespace Exiv2 {
ul2Data(buf + 4, pTiffEntry->count(), byteOrder);
// Move data to offset field, if it fits and is not yet there.
if (pTiffEntry->size() <= 4 && buf + 8 != pTiffEntry->pData()) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Copying data for tag " << pTiffEntry->tag()
<< " to offset area.\n";
#endif
Expand Down Expand Up @@ -843,7 +843,7 @@ namespace Exiv2 {
}
else {
setDirty();
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "DELETING " << key << ", idx = " << object->idx() << "\n";
#endif
}
Expand All @@ -870,7 +870,7 @@ namespace Exiv2 {
if (del_ && pos != exifData_.end()) {
exifData_.erase(pos);
}
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "\n";
#endif
} // TiffEncoder::encodeTiffComponent
Expand All @@ -894,15 +894,15 @@ namespace Exiv2 {
assert(object->pValue());
if ( object->sizeDataArea_
< static_cast<uint32_t>(object->pValue()->sizeDataArea())) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
ExifKey key(object->tag(), groupName(object->group()));
std::cerr << "DATAAREA GREW " << key << "\n";
#endif
setDirty();
}
else {
// Write the new dataarea, fill with 0x0
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
ExifKey key(object->tag(), groupName(object->group()));
std::cerr << "Writing data area for " << key << "\n";
#endif
Expand All @@ -929,14 +929,14 @@ namespace Exiv2 {
uint32_t sizeDataArea = object->pValue()->sizeDataArea();

if (sizeDataArea > 0 && writeMethod() == wmNonIntrusive) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "\t DATAAREA IS SET (NON-INTRUSIVE WRITING)";
#endif
setDirty();
}

if (sizeDataArea > 0 && writeMethod() == wmIntrusive) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "\t DATAAREA IS SET (INTRUSIVE WRITING)";
#endif
// Set pseudo strips (without a data pointer) from the size tag
Expand Down Expand Up @@ -972,7 +972,7 @@ namespace Exiv2 {
}

if (sizeDataArea == 0 && writeMethod() == wmIntrusive) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "\t USE STRIPS FROM SOURCE TREE IMAGE ENTRY";
#endif
// Set strips from source tree
Expand Down Expand Up @@ -1015,18 +1015,18 @@ namespace Exiv2 {
assert(object != 0);
assert(datum != 0);

#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
bool tooLarge = false;
#endif
uint32_t newSize = datum->size();
if (newSize > object->size_) { // value doesn't fit, encode for intrusive writing
setDirty();
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
tooLarge = true;
#endif
}
object->updateValue(datum->getValue(), byteOrder()); // clones the value
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
ExifKey key(object->tag(), groupName(object->group()));
std::cerr << "UPDATING DATA " << key;
if (tooLarge) {
Expand All @@ -1044,15 +1044,15 @@ namespace Exiv2 {
if (newSize > object->size_) { // value doesn't fit, encode for intrusive writing
setDirty();
object->updateValue(datum->getValue(), byteOrder()); // clones the value
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
ExifKey key(object->tag(), groupName(object->group()));
std::cerr << "UPDATING DATA " << key;
std::cerr << "\t\t\t ALLOCATED " << object->size() << " BYTES";
#endif
}
else {
object->setValue(datum->getValue()); // clones the value
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
ExifKey key(object->tag(), groupName(object->group()));
std::cerr << "NOT UPDATING " << key;
std::cerr << "\t\t\t PRESERVE VALUE DATA";
Expand Down Expand Up @@ -1098,7 +1098,7 @@ namespace Exiv2 {
TiffCreator::getPath(tiffPath, i->tag(), group, root);
TiffComponent* tc = pRootDir->addPath(i->tag(), tiffPath, pRootDir);
TiffEntryBase* object = dynamic_cast<TiffEntryBase*>(tc);
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
if (object == 0) {
std::cerr << "Warning: addPath() didn't add an entry for "
<< i->groupName()
Expand Down Expand Up @@ -1425,11 +1425,11 @@ namespace Exiv2 {
EXV_ERROR << "Failed to read "
<< groupName(object->ifd_.group())
<< " IFD Makernote header.\n";
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
if (static_cast<uint32_t>(pLast_ - object->start()) >= 16) {
hexdump(std::cerr, object->start(), 16);
}
#endif // DEBUG
#endif // EXIV2_DEBUG_MESSAGES
#endif // SUPPRESS_WARNINGS
setGo(geKnownMakernote, false);
return;
Expand Down
13 changes: 7 additions & 6 deletions src/webpimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ namespace Exiv2 {
if (!io_->isopen()) throw Error(kerInputDataReadFailed);
if (!outIo.isopen()) throw Error(kerImageWriteFailed);

#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Writing metadata" << std::endl;
#endif

Expand Down Expand Up @@ -518,7 +518,7 @@ namespace Exiv2 {
byte size_buff[WEBP_TAG_SIZE];
bool has_canvas_data = false;

#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Reading metadata" << std::endl;
#endif

Expand Down Expand Up @@ -674,7 +674,7 @@ namespace Exiv2 {

memcpy(rawExifData + offset, payload.pData_, payload.size_);

#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Display Hex Dump [size:" << (unsigned long)size << "]" << std::endl;
std::cout << Internal::binaryToHex(rawExifData, size);
#endif
Expand Down Expand Up @@ -703,7 +703,7 @@ namespace Exiv2 {
EXV_WARNING << "Failed to decode XMP metadata." << std::endl;
#endif
} else {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cout << "Display Hex Dump [size:" << (unsigned long)payload.size_ << "]" << std::endl;
std::cout << Internal::binaryToHex(payload.pData_, payload.size_);
#endif
Expand Down Expand Up @@ -827,8 +827,9 @@ namespace Exiv2 {
}
}

long WebPImage::getHeaderOffset(byte *data, long data_size,
byte *header, long header_size) {
long WebPImage::getHeaderOffset(byte* data, long data_size, byte* header, long header_size)
{
if (data_size < header_size) { return -1; }
long pos = -1;
for (long i=0; i < data_size - header_size; i++) {
if (memcmp(header, &data[i], header_size) == 0) {
Expand Down
6 changes: 3 additions & 3 deletions src/xmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ namespace Exiv2 {
// Register custom namespaces with XMP-SDK
for (XmpProperties::NsRegistry::iterator i = XmpProperties::nsRegistry_.begin();
i != XmpProperties::nsRegistry_.end(); ++i) {
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Registering " << i->second.prefix_ << " : " << i->first << "\n";
#endif
registerNs(i->first, i->second.prefix_);
Expand Down Expand Up @@ -930,7 +930,7 @@ namespace {
return var;
}

#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
void printNode(const std::string& schemaNs,
const std::string& propPath,
const std::string& propValue,
Expand Down Expand Up @@ -973,7 +973,7 @@ namespace {
const std::string& ,
const XMP_OptionBits& )
{}
#endif // DEBUG
#endif // EXIV2_DEBUG_MESSAGES

Exiv2::XmpKey::AutoPtr makeXmpKey(const std::string& schemaNs,
const std::string& propPath)
Expand Down
2 changes: 1 addition & 1 deletion src/xmpsidecar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace Exiv2 {

void XmpSidecar::readMetadata()
{
#ifdef DEBUG
#ifdef EXIV2_DEBUG_MESSAGES
std::cerr << "Reading XMP file " << io_->path() << "\n";
#endif
if (io_->open() != 0) {
Expand Down
Binary file added test/data/issue_943_poc1.mrm
Binary file not shown.
Binary file added test/data/issue_943_poc2.mrm
Binary file not shown.
Binary file added test/data/issue_960.poc.webp
Binary file not shown.
25 changes: 25 additions & 0 deletions tests/bugfixes/github/test_issue_943.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-

from system_tests import CaseMeta, path


class MrmImageLargeAllocation(metaclass=CaseMeta):
"""
Regression test for the bug described in:
https://github.com/Exiv2/exiv2/pull/943
"""
url = "https://github.com/Exiv2/exiv2/pull/943"

filename1 = path("$data_path/issue_943_poc1.mrm")
filename2 = path("$data_path/issue_943_poc2.mrm")
commands = ["$exiv2 $filename1", "$exiv2 $filename2"]
stdout = ["",""]
stderr = [
"""Exiv2 exception in print action for file $filename1:
Failed to read image data
""",
"""Exiv2 exception in print action for file $filename2:
Failed to read image data
"""
]
retval = [1,1]
22 changes: 22 additions & 0 deletions tests/bugfixes/github/test_issue_960.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-

from system_tests import CaseMeta, path


class WebPImageGetHeaderOffset(metaclass=CaseMeta):
"""
Regression test for the bug described in:
https://github.com/Exiv2/exiv2/pull/960
"""
url = "https://github.com/Exiv2/exiv2/pull/960"

filename1 = path("$data_path/issue_960.poc.webp")
commands = ["$exiv2 $filename1"]
stdout = [""]
stderr = [
"""Warning: Failed to decode Exif metadata.
Exiv2 exception in print action for file $filename1:
$kerCorruptedMetadata
"""
]
retval = [1]
35 changes: 32 additions & 3 deletions unitTests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
find_package(GTest REQUIRED)

get_target_property(exiv2lib_SOURCES exiv2lib SOURCES)
get_target_property(exiv2lib_int_SOURCES exiv2lib_int SOURCES)
get_target_property(exiv2lib_COMPILE_DEFINITIONS exiv2lib COMPILE_DEFINITIONS)
get_target_property(exiv2lib_INCLUDE_DIRECTORIES exiv2lib INCLUDE_DIRECTORIES)
get_target_property(exiv2lib_LINK_LIBRARIES exiv2lib LINK_LIBRARIES)

set(unit_tests_exiv2lib_SOURCES)
foreach(source IN LISTS exiv2lib_SOURCES exiv2lib_int_SOURCES)
if(source MATCHES "\.(c|cpp|h|hpp)$")
if(source MATCHES ".*/.*")
list(APPEND unit_tests_exiv2lib_SOURCES "${source}")
else()
list(APPEND unit_tests_exiv2lib_SOURCES "../src/${source}")
endif()
endif()
endforeach()

add_executable(unit_tests mainTestRunner.cpp
gtestwrapper.h
test_basicio.cpp
test_types.cpp
test_tiffheader.cpp
test_futils.cpp
Expand All @@ -14,13 +32,24 @@ add_executable(unit_tests mainTestRunner.cpp
test_helper_functions.cpp
test_slice.cpp
test_image_int.cpp
$<TARGET_OBJECTS:exiv2lib_int>
${unit_tests_exiv2lib_SOURCES}
)

target_compile_definitions(unit_tests PRIVATE exiv2lib_STATIC)

if (exiv2lib_COMPILE_DEFINITIONS)
target_compile_definitions(unit_tests PRIVATE ${exiv2lib_COMPILE_DEFINITIONS})
endif ()

target_include_directories(unit_tests
PRIVATE
${exiv2lib_INCLUDE_DIRECTORIES}
)

#TODO Use GTest::GTest once we upgrade the minimum CMake version required
target_link_libraries(unit_tests
PRIVATE
exiv2lib
${exiv2lib_LINK_LIBRARIES}
${GTEST_BOTH_LIBRARIES}
)

Expand Down Expand Up @@ -50,4 +79,4 @@ endif()

if (MSVC)
set_target_properties(unit_tests PROPERTIES LINK_FLAGS "/ignore:4099")
endif()
endif()
81 changes: 81 additions & 0 deletions unitTests/test_basicio.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#include <exiv2/basicio.hpp>

#include "gtestwrapper.h"

using namespace Exiv2;

TEST(MemIo, seek_out_of_bounds_00)
{
byte buf[1024];
memset(buf, 0, sizeof(buf));

MemIo io(buf, sizeof(buf));
ASSERT_FALSE(io.eof());

// Regression test for bug reported in https://github.com/Exiv2/exiv2/pull/945
// The problem is that MemIo::seek() does not check that the new offset is
// in bounds.
byte tmp[16];
ASSERT_EQ(io.seek(0x10000000, BasicIo::beg), 1);
ASSERT_TRUE(io.eof());

// The seek was invalid, so the offset didn't change and this read still works.
const long sizeTmp = static_cast<long>(sizeof(sizeTmp));
ASSERT_EQ(io.read(tmp, sizeTmp), sizeTmp);
}

TEST(MemIo, seek_out_of_bounds_01)
{
byte buf[1024];
memset(buf, 0, sizeof(buf));

MemIo io(buf, sizeof(buf));
ASSERT_FALSE(io.eof());

byte tmp[16];

// Seek to the end of the file.
ASSERT_EQ(io.seek(0, BasicIo::end), 0);
ASSERT_EQ(io.read(tmp, sizeof(tmp)), 0);

// Try to seek past the end of the file.
ASSERT_EQ(io.seek(0x10000000, BasicIo::end), 1);
ASSERT_TRUE(io.eof());
ASSERT_EQ(io.read(tmp, sizeof(tmp)), 0);
}

TEST(MemIo, seek_out_of_bounds_02)
{
byte buf[1024];
memset(buf, 0, sizeof(buf));

MemIo io(buf, sizeof(buf));
ASSERT_FALSE(io.eof());

byte tmp[16];

// Try to seek past the end of the file.
ASSERT_EQ(io.seek(0x10000000, BasicIo::cur), 1);
ASSERT_TRUE(io.eof());
// The seek was invalid, so the offset didn't change and this read still works.
const long sizeTmp = static_cast<long>(sizeof(sizeTmp));
ASSERT_EQ(io.read(tmp, sizeTmp), sizeTmp);
}

TEST(MemIo, seek_out_of_bounds_03)
{
byte buf[1024];
memset(buf, 0, sizeof(buf));

MemIo io(buf, sizeof(buf));
ASSERT_FALSE(io.eof());

byte tmp[16];

// Try to seek past the beginning of the file.
ASSERT_EQ(io.seek(-0x10000000, BasicIo::cur), 1);
ASSERT_FALSE(io.eof());
// The seek was invalid, so the offset didn't change and this read still works.
const long sizeTmp = static_cast<long>(sizeof(sizeTmp));
ASSERT_EQ(io.read(tmp, sizeTmp), sizeTmp);
}