Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/app_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "app_utils.hpp"
#include <climits>
#include <cstdint>
#include <cstdlib>
#include <limits>

Expand Down
1 change: 0 additions & 1 deletion app/exiv2app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <exiv2/exiv2.hpp>

#include "getopt.hpp"
#include "types.hpp"

// + standard includes
#include <iostream>
Expand Down
44 changes: 22 additions & 22 deletions include/exiv2/basicio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
// included header files
#include "config.h"
#include "error.hpp"
#include "types.hpp"

// + standard includes
#include <memory>

// *****************************************************************************
// namespace extensions
namespace Exiv2 {
struct DataBuf;
// *****************************************************************************
// class definitions

Expand Down Expand Up @@ -77,7 +77,7 @@ class EXIV2API BasicIo {
@return Number of bytes written to IO source successfully;<BR>
0 if failure;
*/
virtual size_t write(const byte* data, size_t wcount) = 0;
virtual size_t write(const unsigned char* data, size_t wcount) = 0;
/*!
@brief Write data that is read from another BasicIo instance to
the IO source. Current IO position is advanced by the number
Expand All @@ -95,7 +95,7 @@ class EXIV2API BasicIo {
@return The value of the byte written if successful;<BR>
EOF if failure;
*/
virtual int putb(byte data) = 0;
virtual int putb(unsigned char data) = 0;
/*!
@brief Read data from the IO source. Reading starts at the current
IO position and the position is advanced by the number of bytes
Expand All @@ -119,7 +119,7 @@ class EXIV2API BasicIo {
@return Number of bytes read from IO source successfully;<BR>
0 if failure;
*/
virtual size_t read(byte* buf, size_t rcount) = 0;
virtual size_t read(unsigned char* buf, size_t rcount) = 0;
/*!
@brief Safe version of `read()` that checks for errors and throws
an exception if the read was unsuccessful.
Expand All @@ -130,7 +130,7 @@ class EXIV2API BasicIo {
read if \em rcount bytes are not available.
@param err Error code to use if an exception is thrown.
*/
void readOrThrow(byte* buf, size_t rcount, ErrorCode err = ErrorCode::kerCorruptedMetadata);
void readOrThrow(unsigned char* buf, size_t rcount, ErrorCode err = ErrorCode::kerCorruptedMetadata);
/*!
@brief Read one byte from the IO source. Current IO position is
advanced by one byte.
Expand Down Expand Up @@ -181,7 +181,7 @@ class EXIV2API BasicIo {
@return A pointer to the mapped area.
@throw Error In case of failure.
*/
virtual byte* mmap(bool isWriteable = false) = 0;
virtual unsigned char* mmap(bool isWriteable = false) = 0;
/*!
@brief Remove a mapping established with mmap(). If the mapped area
is writeable, this ensures that changes are written back.
Expand Down Expand Up @@ -230,7 +230,7 @@ class EXIV2API BasicIo {
/*!
@brief this is allocated and populated by mmap()
*/
byte* bigBlock_{};
unsigned char* bigBlock_{};

//@}
}; // class BasicIo
Expand Down Expand Up @@ -332,7 +332,7 @@ class EXIV2API FileIo : public BasicIo {
@return Number of bytes written to the file successfully;<BR>
0 if failure;
*/
size_t write(const byte* data, size_t wcount) override;
size_t write(const unsigned char* data, size_t wcount) override;
/*!
@brief Write data that is read from another BasicIo instance to
the file. The file position is advanced by the number
Expand All @@ -350,7 +350,7 @@ class EXIV2API FileIo : public BasicIo {
@return The value of the byte written if successful;<BR>
EOF if failure;
*/
int putb(byte data) override;
int putb(unsigned char data) override;
/*!
@brief Read data from the file. Reading starts at the current
file position and the position is advanced by the number of
Expand All @@ -374,7 +374,7 @@ class EXIV2API FileIo : public BasicIo {
@return Number of bytes read from the file successfully;<BR>
0 if failure;
*/
size_t read(byte* buf, size_t rcount) override;
size_t read(unsigned char* buf, size_t rcount) override;
/*!
@brief Read one byte from the file. The file position is
advanced by one byte.
Expand Down Expand Up @@ -415,7 +415,7 @@ class EXIV2API FileIo : public BasicIo {
@return A pointer to the mapped area.
@throw Error In case of failure.
*/
byte* mmap(bool isWriteable = false) override;
unsigned char* mmap(bool isWriteable = false) override;
/*!
@brief Remove a mapping established with mmap(). If the mapped area is
writeable, this ensures that changes are written back to the
Expand Down Expand Up @@ -499,7 +499,7 @@ class EXIV2API MemIo : public BasicIo {
@param data Pointer to data. Data must be at least \em size bytes long
@param size Number of bytes to copy.
*/
MemIo(const byte* data, size_t size);
MemIo(const unsigned char* data, size_t size);
//! Destructor. Releases all managed memory
~MemIo() override;
//@}
Expand Down Expand Up @@ -528,7 +528,7 @@ class EXIV2API MemIo : public BasicIo {
@return Number of bytes written to the memory block successfully;<BR>
0 if failure;
*/
size_t write(const byte* data, size_t wcount) override;
size_t write(const unsigned char* data, size_t wcount) override;
/*!
@brief Write data that is read from another BasicIo instance to
the memory block. If needed, the size of the internal memory
Expand All @@ -547,7 +547,7 @@ class EXIV2API MemIo : public BasicIo {
@return The value of the byte written if successful;<BR>
EOF if failure;
*/
int putb(byte data) override;
int putb(unsigned char data) override;
/*!
@brief Read data from the memory block. Reading starts at the current
IO position and the position is advanced by the number of
Expand All @@ -571,7 +571,7 @@ class EXIV2API MemIo : public BasicIo {
@return Number of bytes read from the memory block successfully;<BR>
0 if failure;
*/
size_t read(byte* buf, size_t rcount) override;
size_t read(unsigned char* buf, size_t rcount) override;
/*!
@brief Read one byte from the memory block. The IO position is
advanced by one byte.
Expand Down Expand Up @@ -606,7 +606,7 @@ class EXIV2API MemIo : public BasicIo {
returned pointer remains valid and allocated as long as the
MemIo object exists.
*/
byte* mmap(bool /*isWriteable*/ = false) override;
unsigned char* mmap(bool /*isWriteable*/ = false) override;
int munmap() override;
//@}

Expand Down Expand Up @@ -739,7 +739,7 @@ class EXIV2API RemoteIo : public BasicIo {
@brief Not support this method.
@return 0 means failure
*/
size_t write(const byte* data, size_t wcount) override;
size_t write(const unsigned char* data, size_t wcount) override;
/*!
@brief Write data that is read from another BasicIo instance to the remote file.

Expand All @@ -760,7 +760,7 @@ class EXIV2API RemoteIo : public BasicIo {
@brief Not support
@return 0 means failure
*/
int putb(byte data) override;
int putb(unsigned char data) override;
/*!
@brief Read data from the memory blocks. Reading starts at the current
IO position and the position is advanced by the number of
Expand Down Expand Up @@ -788,7 +788,7 @@ class EXIV2API RemoteIo : public BasicIo {
@return Number of bytes read from the memory block successfully;<BR>
0 if failure;
*/
size_t read(byte* buf, size_t rcount) override;
size_t read(unsigned char* buf, size_t rcount) override;
/*!
@brief Read one byte from the memory blocks. The IO position is
advanced by one byte.
Expand Down Expand Up @@ -820,7 +820,7 @@ class EXIV2API RemoteIo : public BasicIo {
@brief Not support
@return NULL
*/
byte* mmap(bool /*isWriteable*/ = false) override;
unsigned char* mmap(bool /*isWriteable*/ = false) override;
/*!
@brief Not support
@return 0
Expand Down Expand Up @@ -913,10 +913,10 @@ class EXIV2API CurlIo : public RemoteIo {

/*!
@brief Write access is only available for some protocols. This method
will call RemoteIo::write(const byte* data, long wcount) if the write
will call RemoteIo::write(const unsigned char* data, long wcount) if the write
access is available for the protocol. Otherwise, it throws the Error.
*/
size_t write(const byte* data, size_t wcount) override;
size_t write(const unsigned char* data, size_t wcount) override;
/*!
@brief Write access is only available for some protocols. This method
will call RemoteIo::write(BasicIo& src) if the write access is available
Expand Down
23 changes: 12 additions & 11 deletions include/exiv2/photoshop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@

#include "exiv2lib_export.h"

#include "types.hpp"

#include <array>
#include <cstddef>
#include <cstdint>

namespace Exiv2 {
// Forward declarations
struct DataBuf;
class IptcData;

/// @brief Helper class, has methods to deal with %Photoshop "Information Resource Blocks" (IRBs).
Expand All @@ -26,13 +27,13 @@ struct EXIV2API Photoshop {
/// @return true if the IRB marker is known
/// @todo This should be an implementation detail and not exposed in the API. An attacker could try to pass
/// a smaller buffer or null pointer.
static bool isIrb(const byte* pPsData);
static bool isIrb(const unsigned char* pPsData);

/// @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;<BR> false otherwise
static bool valid(const byte* pPsData, size_t sizePsData);
static bool valid(const unsigned char* pPsData, size_t sizePsData);

/// @brief Locates the data for a %Photoshop tag in a %Photoshop formatted memory buffer.
/// Operates on raw data to simplify reuse.
Expand All @@ -47,23 +48,23 @@ struct EXIV2API Photoshop {
/// @return 0 if successful;<BR>
/// 3 if no data for psTag was found in pPsData;<BR>
/// -2 if the pPsData buffer does not contain valid data.
static int locateIrb(const byte* pPsData, size_t sizePsData, uint16_t psTag, const byte** record, uint32_t& sizeHdr,
uint32_t& sizeData);
static int locateIrb(const unsigned char* pPsData, size_t sizePsData, uint16_t psTag, const unsigned char** record,
uint32_t& sizeHdr, uint32_t& sizeData);

/// @brief Forwards to locateIrb() with \em psTag = \em iptc_
static int locateIptcIrb(const byte* pPsData, size_t sizePsData, const byte** record, uint32_t& sizeHdr,
uint32_t& sizeData);
static int locateIptcIrb(const unsigned char* pPsData, size_t sizePsData, const unsigned char** record,
uint32_t& sizeHdr, uint32_t& sizeData);

/// @brief Forwards to locatePreviewIrb() with \em psTag = \em preview_
static int locatePreviewIrb(const byte* pPsData, size_t sizePsData, const byte** record, uint32_t& sizeHdr,
uint32_t& sizeData);
static int locatePreviewIrb(const unsigned char* pPsData, size_t sizePsData, const unsigned char** record,
uint32_t& sizeHdr, uint32_t& sizeData);

/// @brief Set the new IPTC IRB, keeps existing IRBs but removes the IPTC block if there is no new IPTC data to write.
/// @param pPsData Existing IRB buffer
/// @param sizePsData Size of the IRB buffer, may be 0
/// @param iptcData Iptc data to embed, may be empty
/// @return A data buffer containing the new IRB buffer, may have 0 size
static DataBuf setIptcIrb(const byte* pPsData, size_t sizePsData, const IptcData& iptcData);
static DataBuf setIptcIrb(const unsigned char* pPsData, size_t sizePsData, const IptcData& iptcData);
};
} // namespace Exiv2

Expand Down
1 change: 0 additions & 1 deletion include/exiv2/preview.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
// namespace extensions
namespace Exiv2 {
class Image;
struct DataBuf;
// *****************************************************************************
// class definitions

Expand Down
6 changes: 3 additions & 3 deletions src/basicio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -930,13 +930,13 @@ std::string XPathIo::writeDataToFile(const std::string& orgPath) {
#endif
std::ofstream fs(path, std::ios::out | std::ios::binary | std::ios::trunc);
// read stdin and write to the temp file.
char readBuf[100 * 1024];
auto readBuf = std::make_unique<char[]>(100 * 1024);
std::streamsize readBufSize = 0;
do {
std::cin.read(readBuf, sizeof(readBuf));
std::cin.read(readBuf.get(), 100 * 1024);
readBufSize = std::cin.gcount();
if (readBufSize > 0) {
fs.write(readBuf, readBufSize);
fs.write(readBuf.get(), readBufSize);
}
} while (readBufSize);
fs.close();
Expand Down
2 changes: 1 addition & 1 deletion src/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ void Converter::cnvExifVersion(const char* from, const char* to) {
std::string value;
value.reserve(count);
for (size_t i = 0; i < count; ++i) {
value.push_back(pos->toInt64(i));
value.push_back(pos->toUint32(i));
}
(*xmpData_)[to] = value;
if (erase_)
Expand Down
4 changes: 3 additions & 1 deletion src/crwimage_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ const CiffComponent::UniquePtr& CiffDirectory::doAdd(UniquePtr component) {
return components_.emplace_back(std::move(component));
} // CiffDirectory::doAdd

const byte CiffHeader::signature_[] = {'H', 'E', 'A', 'P', 'C', 'C', 'D', 'R'};

void CiffHeader::read(const byte* pData, size_t size) {
if (size < 14)
throw Error(ErrorCode::kerNotACrwImage);
Expand Down Expand Up @@ -281,7 +283,7 @@ void CiffHeader::write(Blob& blob) const {
ul2Data(buf, offset_, byteOrder_);
append(blob, buf, 4);
o += 4;
append(blob, reinterpret_cast<const byte*>(signature_), 8);
append(blob, signature_, 8);
o += 8;
// Pad as needed
if (!pPadding_.empty()) {
Expand Down
4 changes: 2 additions & 2 deletions src/crwimage_int.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ class CiffHeader {
//@}

//! Return a pointer to the Canon CRW signature.
static const char* signature() {
static auto signature() {
return signature_;
}

Expand Down Expand Up @@ -451,7 +451,7 @@ class CiffHeader {

private:
// DATA
static constexpr auto signature_ = "HEAPCCDR"; //!< Canon CRW signature
static const byte signature_[]; //!< Canon CRW signature

std::unique_ptr<CiffDirectory> pRootDir_; //!< Pointer to the root directory
ByteOrder byteOrder_ = littleEndian; //!< Applicable byte order
Expand Down
2 changes: 2 additions & 0 deletions src/error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
// + standard includes
#include <array>
#include <iostream>
#include <string>
#include <utility>

namespace {
//! Complete list of Exiv2 exception error messages
Expand Down
3 changes: 2 additions & 1 deletion src/helper_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "basicio.hpp"
#include "convert.hpp"
#include "enforce.hpp"
#include "types.hpp"

#include <cstring>
#include <numeric>
Expand All @@ -20,7 +21,7 @@ std::string string_from_unterminated(const char* data, size_t data_length) {
namespace Exiv2 {
uint64_t readQWORDTag(const BasicIo::UniquePtr& io) {
Internal::enforce(QWORD <= io->size() - io->tell(), Exiv2::ErrorCode::kerCorruptedMetadata);
DataBuf FieldBuf = io->read(QWORD);
auto FieldBuf = io->read(QWORD);
return FieldBuf.read_uint64(0, littleEndian);
}

Expand Down
3 changes: 3 additions & 0 deletions src/pgfimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
#include "error.hpp"
#include "futils.hpp"
#include "image.hpp"
#include "types.hpp"

#include <array>
#include <cstdint>
#include <cstring>
#include <limits>
#include <utility>

#ifdef EXIV2_DEBUG_MESSAGES
#include <iostream>
Expand Down
Loading