Skip to content

Commit 6758e72

Browse files
Merge branch 'main' into fix_exiv2_-pR
2 parents 1535357 + fde8ed0 commit 6758e72

21 files changed

+578
-127
lines changed

conanfile.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ def configure(self):
2222

2323
def requirements(self):
2424
self.requires('zlib/1.2.11')
25-
self.requires('libcurl/7.75.0')
25+
26+
if self.options.webready:
27+
self.requires('libcurl/7.79.0')
2628

2729
if os_info.is_windows and self.options.iconv:
2830
self.requires('libiconv/1.16')
@@ -35,7 +37,7 @@ def requirements(self):
3537
if self.options.xmp:
3638
self.requires('XmpSdk/2016.7@piponazo/stable') # from conan-piponazo
3739
else:
38-
self.requires('expat/2.3.0')
40+
self.requires('expat/2.4.1')
3941

4042
def imports(self):
4143
self.copy('*.dll', dst='bin', src='bin')

doc/templates/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ TABLES = Exif \
7676
NikonFl1 \
7777
NikonFl2 \
7878
NikonFl3 \
79+
NikonFl7 \
7980
NikonSiD80 \
8081
NikonSiD40 \
8182
NikonSiD300a \

doc/templates/tags-nikon.html.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ __NikonFl2__
9191
__NikonFl3__
9292
<br>
9393

94+
<h3>Nikon Flash Info 7 Tags (for version 0107 and 0108)</h3>
95+
<p>Click on a column header to sort the table.</p>
96+
__NikonFl7__
97+
<br>
98+
9499
<h3>Nikon Shot Info D80 Tags</h3>
95100
<p>Click on a column header to sort the table.</p>
96101
__NikonSiD80__

exiv2.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -793,19 +793,19 @@ Image CanonCf Nikon2 NikonPc OlympusFe9 SonyMisc3c
793793
Image2 CanonCs Nikon3 NikonPreview OlympusFi SonyMinolta
794794
Image3 CanonFi NikonAFT NikonSi01xx OlympusIp SonySInfo1
795795
Iop CanonPa NikonAf NikonSi02xx OlympusRd
796-
MakerNote CanonPi NikonAf NikonSiD300a OlympusRd2 Samsung2
797-
MpfInfo CanonPr NikonAf2 NikonSiD300b OlympusRi SamsungPictureWizard
798-
Photo CanonSi NikonAf22 NikonSiD40 SamsungPreview
799-
SubImage1 CanonTi NikonCb1 NikonSiD80 Sigma
800-
SubImage2 NikonCb2 NikonVr
801-
SubImage3 Casio NikonCb2a NikonWt Sony1
802-
SubImage4 Casio2 NikonCb2b Sony1Cs
803-
SubImage5 NikonCb3 Olympus Sony1Cs2
804-
SubImage6 Minolta NikonCb4 Olympus2 Sony1MltCs7D
805-
SubImage7 MinoltaCs5D NikonFi OlympusCs Sony1MltCsA100
806-
SubImage8 MinoltaCs7D NikonFl1 OlympusEq Sony1MltCsNew
807-
SubImage9 MinoltaCsNew NikonFl2 OlympusFe1 Sony1MltCsOld
808-
SubThumb1 MinoltaCsOld NikonFl3 OlympusFe2 Sony2
796+
MakerNote CanonPi NikonAf2 NikonSiD300a OlympusRd2 Samsung2
797+
MpfInfo CanonPr NikonAf22 NikonSiD300b OlympusRi SamsungPictureWizard
798+
Photo CanonSi NikonCb1 NikonSiD40 SamsungPreview
799+
SubImage1 CanonTi NikonCb2 NikonSiD80 Sigma
800+
SubImage2 NikonCb2a NikonVr
801+
SubImage3 Casio NikonCb2b NikonWt Sony1
802+
SubImage4 Casio2 NikonCb3 Sony1Cs
803+
SubImage5 NikonCb4 Olympus Sony1Cs2
804+
SubImage6 Minolta NikonFi Olympus2 Sony1MltCs7D
805+
SubImage7 MinoltaCs5D NikonFl1 OlympusCs Sony1MltCsA100
806+
SubImage8 MinoltaCs7D NikonFl2 OlympusEq Sony1MltCsNew
807+
SubImage9 MinoltaCsNew NikonFl3 OlympusFe1 Sony1MltCsOld
808+
SubThumb1 MinoltaCsOld NikonFl7 OlympusFe2 Sony2
809809
Thumbnail NikonIi OlympusFe3 Sony2Cs
810810
Panasonic NikonLd1 OlympusFe4 Sony2Cs2
811811
Pentax PanasonicRaw NikonLd2 OlympusFe5 Sony2010e

include/exiv2/basicio.hpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "exiv2lib_export.h"
2828

2929
// included header files
30+
#include "error.hpp"
3031
#include "types.hpp"
3132

3233
// + standard includes
@@ -142,6 +143,17 @@ namespace Exiv2 {
142143
0 if failure;
143144
*/
144145
virtual long read(byte* buf, long rcount) = 0;
146+
/*!
147+
@brief Safe version of `read()` that checks for errors and throws
148+
an exception if the read was unsuccessful.
149+
@param buf Pointer to a block of memory into which the read data
150+
is stored. The memory block must be at least \em rcount bytes
151+
long.
152+
@param rcount Maximum number of bytes to read. Fewer bytes may be
153+
read if \em rcount bytes are not available.
154+
@param err Error code to use if an exception is thrown.
155+
*/
156+
void readOrThrow(byte* buf, long rcount, ErrorCode err);
145157
/*!
146158
@brief Read one byte from the IO source. Current IO position is
147159
advanced by one byte.
@@ -176,6 +188,19 @@ namespace Exiv2 {
176188
#else
177189
virtual int seek(long offset, Position pos) = 0;
178190
#endif
191+
/*!
192+
@brief Safe version of `seek()` that checks for errors and throws
193+
an exception if the seek was unsuccessful.
194+
@param offset Number of bytes to move the position relative
195+
to the starting position specified by \em pos
196+
@param pos Position from which the seek should start
197+
@param err Error code to use if an exception is thrown.
198+
*/
199+
#if defined(_MSC_VER)
200+
void seekOrThrow(int64_t offset, Position pos, ErrorCode err);
201+
#else
202+
void seekOrThrow(long offset, Position pos, ErrorCode err);
203+
#endif
179204

180205
/*!
181206
@brief Direct access to the IO data. For files, this is done by

src/basicio.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "futils.hpp"
2929
#include "types.hpp"
3030
#include "error.hpp"
31+
#include "enforce.hpp"
3132
#include "http.hpp"
3233
#include "properties.hpp"
3334
#include "image_int.hpp"
@@ -77,6 +78,21 @@ using nlink_t = short;
7778
// *****************************************************************************
7879
// class member definitions
7980
namespace Exiv2 {
81+
void BasicIo::readOrThrow(byte* buf, long rcount, ErrorCode err) {
82+
const long nread = read(buf, rcount);
83+
enforce(nread == rcount, err);
84+
enforce(!error(), err);
85+
}
86+
87+
#if defined(_MSC_VER)
88+
void BasicIo::seekOrThrow(int64_t offset, Position pos, ErrorCode err) {
89+
#else
90+
void BasicIo::seekOrThrow(long offset, Position pos, ErrorCode err) {
91+
#endif
92+
const int r = seek(offset, pos);
93+
enforce(r == 0, err);
94+
}
95+
8096
//! Internal Pimpl structure of class FileIo.
8197
class FileIo::Impl {
8298
public:

src/image.cpp

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,6 @@ namespace {
138138
// *****************************************************************************
139139
// class member definitions
140140
namespace Exiv2 {
141-
// BasicIo::read() with error checking
142-
static void readOrThrow(BasicIo& iIo, byte* buf, long rcount, ErrorCode err) {
143-
const long nread = iIo.read(buf, rcount);
144-
enforce(nread == rcount, err);
145-
enforce(!iIo.error(), err);
146-
}
147-
148-
// BasicIo::seek() with error checking
149-
static void seekOrThrow(BasicIo& iIo, long offset, BasicIo::Position pos, ErrorCode err) {
150-
const int r = iIo.seek(offset, pos);
151-
enforce(r == 0, err);
152-
}
153-
154141
Image::Image(int imageType, uint16_t supportedMetadata, BasicIo::UniquePtr io)
155142
: io_(std::move(io)),
156143
pixelWidth_(0),
@@ -342,8 +329,8 @@ namespace Exiv2 {
342329

343330
do {
344331
// Read top of directory
345-
seekOrThrow(io, start, BasicIo::beg, kerCorruptedMetadata);
346-
readOrThrow(io, dir.data(), 2, kerCorruptedMetadata);
332+
io.seekOrThrow(start, BasicIo::beg, kerCorruptedMetadata);
333+
io.readOrThrow(dir.data(), 2, kerCorruptedMetadata);
347334
uint16_t dirLength = byteSwap2(dir,0,bSwap);
348335
// Prevent infinite loops. (GHSA-m479-7frc-gqqg)
349336
enforce(dirLength > 0, kerCorruptedMetadata);
@@ -369,7 +356,7 @@ namespace Exiv2 {
369356
}
370357
bFirst = false;
371358

372-
readOrThrow(io, dir.data(), 12, kerCorruptedMetadata);
359+
io.readOrThrow(dir.data(), 12, kerCorruptedMetadata);
373360
uint16_t tag = byteSwap2(dir,0,bSwap);
374361
uint16_t type = byteSwap2(dir,2,bSwap);
375362
uint32_t count = byteSwap4(dir,4,bSwap);
@@ -420,9 +407,9 @@ namespace Exiv2 {
420407

421408
if ( bOffsetIsPointer ) { // read into buffer
422409
const long restore = io.tell(); // save
423-
seekOrThrow(io, offset, BasicIo::beg, kerCorruptedMetadata); // position
424-
readOrThrow(io, buf.data(), static_cast<long>(count_x_size), kerCorruptedMetadata); // read
425-
seekOrThrow(io, restore, BasicIo::beg, kerCorruptedMetadata); // restore
410+
io.seekOrThrow(offset, BasicIo::beg, kerCorruptedMetadata); // position
411+
io.readOrThrow(buf.data(), static_cast<long>(count_x_size), kerCorruptedMetadata); // read
412+
io.seekOrThrow(restore, BasicIo::beg, kerCorruptedMetadata); // restore
426413
}
427414

428415
if ( bPrint ) {
@@ -464,7 +451,7 @@ namespace Exiv2 {
464451
const long restore = io.tell();
465452
offset = byteSwap4(buf,k*size,bSwap);
466453
printIFDStructure(io,out,option,offset,bSwap,c,depth);
467-
seekOrThrow(io, restore, BasicIo::beg, kerCorruptedMetadata);
454+
io.seekOrThrow(restore, BasicIo::beg, kerCorruptedMetadata);
468455
}
469456
} else if ( option == kpsRecursive && tag == 0x83bb /* IPTCNAA */ ) {
470457
if (count > 0) {
@@ -473,11 +460,11 @@ namespace Exiv2 {
473460
}
474461

475462
const long restore = io.tell();
476-
seekOrThrow(io, offset, BasicIo::beg, kerCorruptedMetadata); // position
463+
io.seekOrThrow(offset, BasicIo::beg, kerCorruptedMetadata); // position
477464
std::vector<byte> bytes(count) ; // allocate memory
478465
// TODO: once we have C++11 use bytes.data()
479-
readOrThrow(io, &bytes[0], count, kerCorruptedMetadata);
480-
seekOrThrow(io, restore, BasicIo::beg, kerCorruptedMetadata);
466+
io.readOrThrow(&bytes[0], count, kerCorruptedMetadata);
467+
io.seekOrThrow(restore, BasicIo::beg, kerCorruptedMetadata);
481468
// TODO: once we have C++11 use bytes.data()
482469
IptcData::printStructure(out, makeSliceUntil(&bytes[0], count), depth);
483470
}
@@ -487,8 +474,8 @@ namespace Exiv2 {
487474
uint32_t jump= 10 ;
488475
byte bytes[20] ;
489476
const auto chars = reinterpret_cast<const char*>(&bytes[0]);
490-
seekOrThrow(io, offset, BasicIo::beg, kerCorruptedMetadata); // position
491-
readOrThrow(io, bytes, jump, kerCorruptedMetadata) ; // read
477+
io.seekOrThrow(offset, BasicIo::beg, kerCorruptedMetadata); // position
478+
io.readOrThrow(bytes, jump, kerCorruptedMetadata) ; // read
492479
bytes[jump]=0 ;
493480

494481
bool bNikon = ::strcmp("Nikon" ,chars) == 0;
@@ -498,17 +485,17 @@ namespace Exiv2 {
498485
// tag is an embedded tiff
499486
const long byteslen = count-jump;
500487
DataBuf bytes(byteslen); // allocate a buffer
501-
readOrThrow(io, bytes.data(), byteslen, kerCorruptedMetadata); // read
488+
io.readOrThrow(bytes.data(), byteslen, kerCorruptedMetadata); // read
502489
MemIo memIo(bytes.c_data(), byteslen) ; // create a file
503490
printTiffStructure(memIo,out,option,depth);
504491
} else {
505492
// tag is an IFD
506493
uint32_t punt = bSony ? 12 : 0 ;
507-
seekOrThrow(io, 0, BasicIo::beg, kerCorruptedMetadata); // position
494+
io.seekOrThrow(0, BasicIo::beg, kerCorruptedMetadata); // position
508495
printIFDStructure(io,out,option,offset+punt,bSwap,c,depth);
509496
}
510497

511-
seekOrThrow(io, restore, BasicIo::beg, kerCorruptedMetadata); // restore
498+
io.seekOrThrow(restore, BasicIo::beg, kerCorruptedMetadata); // restore
512499
}
513500
}
514501

@@ -521,7 +508,7 @@ namespace Exiv2 {
521508
}
522509
}
523510
if ( start ) {
524-
readOrThrow(io, dir.data(), 4, kerCorruptedMetadata);
511+
io.readOrThrow(dir.data(), 4, kerCorruptedMetadata);
525512
start = byteSwap4(dir,0,bSwap);
526513
}
527514
} while (start) ;
@@ -541,7 +528,7 @@ namespace Exiv2 {
541528
DataBuf dir(dirSize);
542529

543530
// read header (we already know for certain that we have a Tiff file)
544-
readOrThrow(io, dir.data(), 8, kerCorruptedMetadata);
531+
io.readOrThrow(dir.data(), 8, kerCorruptedMetadata);
545532
char c = static_cast<char>(dir.read_uint8(0));
546533
bool bSwap = ( c == 'M' && isLittleEndianPlatform() )
547534
|| ( c == 'I' && isBigEndianPlatform() )

src/jpgimage.cpp

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,6 @@ namespace Exiv2 {
9494
constexpr uint16_t Photoshop::iptc_ = 0x0404;
9595
constexpr uint16_t Photoshop::preview_ = 0x040c;
9696

97-
// BasicIo::read() with error checking
98-
static void readOrThrow(BasicIo& iIo, byte* buf, long rcount, ErrorCode err) {
99-
const long nread = iIo.read(buf, rcount);
100-
enforce(nread == rcount, err);
101-
enforce(!iIo.error(), err);
102-
}
103-
104-
// BasicIo::seek() with error checking
105-
static void seekOrThrow(BasicIo& iIo, long offset, BasicIo::Position pos, ErrorCode err) {
106-
const int r = iIo.seek(offset, pos);
107-
enforce(r == 0, err);
108-
}
109-
11097
static inline bool inRange(int lo,int value, int hi)
11198
{
11299
return lo<=value && value <= hi;
@@ -389,7 +376,7 @@ namespace Exiv2 {
389376
byte sizebuf[2];
390377
uint16_t size = 0;
391378
if (markerHasLength(marker)) {
392-
readOrThrow(*io_, sizebuf, 2, kerFailedToReadImageData);
379+
io_->readOrThrow(sizebuf, 2, kerFailedToReadImageData);
393380
size = getUShort(sizebuf, bigEndian);
394381
// `size` is the size of the segment, including the 2-byte size field
395382
// that we just read.
@@ -399,7 +386,7 @@ namespace Exiv2 {
399386
// Read the rest of the segment.
400387
DataBuf buf(size);
401388
if (size > 0) {
402-
readOrThrow(*io_, buf.data(2), size - 2, kerFailedToReadImageData);
389+
io_->readOrThrow(buf.data(2), size - 2, kerFailedToReadImageData);
403390
buf.copyBytes(0, sizebuf, 2);
404391
}
405392

@@ -616,7 +603,7 @@ namespace Exiv2 {
616603
byte sizebuf[2];
617604
uint16_t size = 0;
618605
if (markerHasLength(marker)) {
619-
readOrThrow(*io_, sizebuf, 2, kerFailedToReadImageData);
606+
io_->readOrThrow(sizebuf, 2, kerFailedToReadImageData);
620607
size = getUShort(sizebuf, bigEndian);
621608
// `size` is the size of the segment, including the 2-byte size field
622609
// that we just read.
@@ -627,7 +614,7 @@ namespace Exiv2 {
627614
DataBuf buf(size);
628615
if (size > 0) {
629616
assert(size >= 2); // enforced above
630-
readOrThrow(*io_, buf.data(2), size - 2, kerFailedToReadImageData);
617+
io_->readOrThrow(buf.data(2), size - 2, kerFailedToReadImageData);
631618
buf.copyBytes(0, sizebuf, 2);
632619
}
633620

@@ -847,16 +834,16 @@ namespace Exiv2 {
847834
#ifdef EXIV2_DEBUG_MESSAGES
848835
std::cout << start << ":" << length << std::endl;
849836
#endif
850-
seekOrThrow(*io_, start, BasicIo::beg, kerFailedToReadImageData);
837+
io_->seekOrThrow(start, BasicIo::beg, kerFailedToReadImageData);
851838
DataBuf buf(length);
852-
readOrThrow(*io_, buf.data(), buf.size(), kerFailedToReadImageData);
839+
io_->readOrThrow(buf.data(), buf.size(), kerFailedToReadImageData);
853840
tempIo->write(buf.c_data(), buf.size());
854841
}
855842
}
856843

857-
seekOrThrow(*io_, 0, BasicIo::beg, kerFailedToReadImageData);
844+
io_->seekOrThrow(0, BasicIo::beg, kerFailedToReadImageData);
858845
io_->transfer(*tempIo); // may throw
859-
seekOrThrow(*io_, 0, BasicIo::beg, kerFailedToReadImageData);
846+
io_->seekOrThrow(0, BasicIo::beg, kerFailedToReadImageData);
860847
readMetadata();
861848
}
862849
} // JpegBase::printStructure
@@ -923,7 +910,7 @@ namespace Exiv2 {
923910
byte sizebuf[2];
924911
uint16_t size = 0;
925912
if (markerHasLength(marker)) {
926-
readOrThrow(*io_, sizebuf, 2, kerFailedToReadImageData);
913+
io_->readOrThrow(sizebuf, 2, kerFailedToReadImageData);
927914
size = getUShort(sizebuf, bigEndian);
928915
// `size` is the size of the segment, including the 2-byte size field
929916
// that we just read.
@@ -934,7 +921,7 @@ namespace Exiv2 {
934921
DataBuf buf(size);
935922
if (size > 0) {
936923
assert(size >= 2); // enforced above
937-
readOrThrow(*io_, buf.data(2), size - 2, kerFailedToReadImageData);
924+
io_->readOrThrow(buf.data(2), size - 2, kerFailedToReadImageData);
938925
buf.copyBytes(0, sizebuf, 2);
939926
}
940927

@@ -1024,7 +1011,7 @@ namespace Exiv2 {
10241011
if (!comment_.empty())
10251012
++search;
10261013

1027-
seekOrThrow(*io_, seek, BasicIo::beg, kerNoImageInInputData);
1014+
io_->seekOrThrow(seek, BasicIo::beg, kerNoImageInInputData);
10281015
count = 0;
10291016
marker = advanceToMarker(kerNoImageInInputData);
10301017

@@ -1037,7 +1024,7 @@ namespace Exiv2 {
10371024
byte sizebuf[2];
10381025
uint16_t size = 0;
10391026
if (markerHasLength(marker)) {
1040-
readOrThrow(*io_, sizebuf, 2, kerFailedToReadImageData);
1027+
io_->readOrThrow(sizebuf, 2, kerFailedToReadImageData);
10411028
size = getUShort(sizebuf, bigEndian);
10421029
// `size` is the size of the segment, including the 2-byte size field
10431030
// that we just read.
@@ -1048,7 +1035,7 @@ namespace Exiv2 {
10481035
DataBuf buf(size);
10491036
if (size > 0) {
10501037
assert(size >= 2); // enforced above
1051-
readOrThrow(*io_, buf.data(2), size - 2, kerFailedToReadImageData);
1038+
io_->readOrThrow(buf.data(2), size - 2, kerFailedToReadImageData);
10521039
buf.copyBytes(0, sizebuf, 2);
10531040
}
10541041

0 commit comments

Comments
 (0)