From bc9d6852107a264540957e2b5929f8a855ad8670 Mon Sep 17 00:00:00 2001 From: Andreas Huggel Date: Sun, 28 Jun 2009 15:44:41 +0000 Subject: [PATCH] 533: Applied patch 4_new_function_Photoshop_valid (Michael Ulbrich, Volker Grabsch) --- src/jpgimage.cpp | 25 +++++++++++++++++++++---- src/jpgimage.hpp | 10 ++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/jpgimage.cpp b/src/jpgimage.cpp index 10ac5b7c..d20930f2 100644 --- a/src/jpgimage.cpp +++ b/src/jpgimage.cpp @@ -87,6 +87,23 @@ namespace Exiv2 { const char Photoshop::bimId_[] = "8BIM"; const uint16_t Photoshop::iptc_ = 0x0404; + bool Photoshop::valid(const byte* pPsData, + long sizePsData) + { + const byte *record = 0; + uint32_t sizeIptc = 0; + uint32_t sizeHdr = 0; + const byte* pCur = pPsData; + const byte* pEnd = pPsData + sizePsData; + int ret = 0; + while (pCur < pEnd + && 0 == (ret = Photoshop::locateIptcIrb(pCur, static_cast(pEnd - pCur), + &record, &sizeHdr, &sizeIptc))) { + pCur = record + sizeHdr + sizeIptc + (sizeIptc & 1); + } + return ret >= 0; + } + // Todo: Generalised from JpegBase::locateIptcData without really understanding // the format (in particular the header). So it remains to be confirmed // if this also makes sense for psTag != Photoshop::iptc @@ -121,8 +138,8 @@ namespace Exiv2 { position += psSize; if (position + 4 > sizePsData) { #ifndef SUPPRESS_WARNINGS - std::cerr << "Error: " - << "Invalid Photoshop IRB\n"; + std::cerr << "Warning: " + << "Invalid or extended Photoshop IRB\n"; #endif return -2; } @@ -130,9 +147,9 @@ namespace Exiv2 { position += 4; if (dataSize > static_cast(sizePsData - position)) { #ifndef SUPPRESS_WARNINGS - std::cerr << "Error: " + std::cerr << "Warning: " << "Invalid Photoshop IRB data size " - << dataSize << "\n"; + << dataSize << " or extended Photoshop IRB\n"; #endif return -2; } diff --git a/src/jpgimage.hpp b/src/jpgimage.hpp index ec043a11..e4a5496a 100644 --- a/src/jpgimage.hpp +++ b/src/jpgimage.hpp @@ -63,6 +63,16 @@ namespace Exiv2 { static const char bimId_[]; //!< %Photoshop marker static const uint16_t iptc_; //!< %Photoshop IPTC marker + /*! + @brief Validates all IRBs + + @param pPsData Existing IRB buffer + @param sizePsData Size of the IRB buffer, may be 0 + @return true if all IRBs are valid;
+ false otherwise + */ + static bool valid(const byte* pPsData, + long sizePsData); /*! @brief Locates the data for a %Photoshop tag in a %Photoshop formated memory buffer. Operates on raw data to simplify reuse.