@@ -74,7 +74,7 @@ BmffImage::BmffImage(BasicIo::UniquePtr io, bool /* create */) :
7474 Image (ImageType::bmff, mdExif | mdIptc | mdXmp, std::move(io)) {
7575} // BmffImage::BmffImage
7676
77- std::string BmffImage::toAscii (long n) {
77+ std::string BmffImage::toAscii (uint32_t n) {
7878 const auto p = reinterpret_cast <const char *>(&n);
7979 std::string result;
8080 for (int i = 0 ; i < 4 ; i++) {
@@ -152,9 +152,9 @@ std::string BmffImage::uuidName(Exiv2::DataBuf& uuid) {
152152 return result;
153153}
154154
155- long BmffImage::boxHandler (std::ostream& out /* = std::cout*/ , Exiv2::PrintStructureOption option /* = kpsNone */ ,
156- long pbox_end, int depth) {
157- long address = io_->tell ();
155+ uint64_t BmffImage::boxHandler (std::ostream& out /* = std::cout*/ , Exiv2::PrintStructureOption option /* = kpsNone */ ,
156+ uint64_t pbox_end, int depth) {
157+ const size_t address = io_->tell ();
158158 // never visit a box twice!
159159 if (depth == 0 )
160160 visits_.clear ();
@@ -198,22 +198,22 @@ long BmffImage::boxHandler(std::ostream& out /* = std::cout*/, Exiv2::PrintStruc
198198 }
199199
200200 // read data in box and restore file position
201- long restore = io_->tell ();
201+ const size_t restore = io_->tell ();
202202 enforce (box_length >= hdrsize, Exiv2::ErrorCode::kerCorruptedMetadata);
203- enforce (box_length - hdrsize <= static_cast < uint64_t >( pbox_end - restore) , Exiv2::ErrorCode::kerCorruptedMetadata);
203+ enforce (box_length - hdrsize <= pbox_end - restore, Exiv2::ErrorCode::kerCorruptedMetadata);
204204
205- const auto buffer_size = static_cast < size_t >( box_length - hdrsize) ;
205+ const auto buffer_size = box_length - hdrsize;
206206 if (skipBox (box_type)) {
207207 if (bTrace) {
208208 out << std::endl;
209209 }
210210 // The enforce() above checks that restore + buffer_size won't
211211 // exceed pbox_end, and by implication, won't exceed LONG_MAX
212- return restore + static_cast < long >( buffer_size) ;
212+ return restore + buffer_size;
213213 }
214214
215- DataBuf data (buffer_size);
216- const long box_end = restore + static_cast < long >( data.size () );
215+ DataBuf data (static_cast < size_t >( buffer_size) );
216+ const size_t box_end = restore + data.size ();
217217 io_->read (data.data (), data.size ());
218218 io_->seek (restore, BasicIo::beg);
219219
@@ -478,26 +478,25 @@ long BmffImage::boxHandler(std::ostream& out /* = std::cout*/, Exiv2::PrintStruc
478478void BmffImage::parseTiff (uint32_t root_tag, uint64_t length, uint64_t start) {
479479 enforce (start <= io_->size (), ErrorCode::kerCorruptedMetadata);
480480 enforce (length <= io_->size () - start, ErrorCode::kerCorruptedMetadata);
481- enforce (start <= std::numeric_limits<uint64_t >::max (), ErrorCode::kerCorruptedMetadata);
482- enforce (length <= std::numeric_limits<uint64_t >::max (), ErrorCode::kerCorruptedMetadata);
481+ enforce (start <= static_cast < uint64_t >( std::numeric_limits<int64_t >::max () ), ErrorCode::kerCorruptedMetadata);
482+ enforce (length <= std::numeric_limits<size_t >::max (), ErrorCode::kerCorruptedMetadata);
483483
484484 // read and parse exif data
485- long restore = io_->tell ();
485+ const size_t restore = io_->tell ();
486486 DataBuf exif (static_cast <size_t >(length));
487- io_->seek (static_cast <long >(start), BasicIo::beg);
487+ io_->seek (static_cast <int64_t >(start), BasicIo::beg);
488488 if (exif.size () > 8 && io_->read (exif.data (), exif.size ()) == exif.size ()) {
489489 // hunt for "II" or "MM"
490- long eof = 0xffffffff ; // impossible value for punt
491- long punt = eof;
490+ const size_t eof = std::numeric_limits< size_t >:: max () ; // impossible value for punt
491+ size_t punt = eof;
492492 for (size_t i = 0 ; i < exif.size () - 8 && punt == eof; i += 2 ) {
493493 if (exif.read_uint8 (i) == exif.read_uint8 (i + 1 ))
494494 if (exif.read_uint8 (i) == ' I' || exif.read_uint8 (i) == ' M' )
495- punt = static_cast < long >(i) ;
495+ punt = i ;
496496 }
497497 if (punt != eof) {
498- Internal::TiffParserWorker::decode (exifData (), iptcData (), xmpData (), exif.c_data (punt),
499- static_cast <uint32_t >(exif.size () - punt), root_tag,
500- Internal::TiffMapping::findDecoder);
498+ Internal::TiffParserWorker::decode (exifData (), iptcData (), xmpData (), exif.c_data (punt), exif.size () - punt,
499+ root_tag, Internal::TiffMapping::findDecoder);
501500 }
502501 }
503502 io_->seek (restore, BasicIo::beg);
@@ -506,7 +505,7 @@ void BmffImage::parseTiff(uint32_t root_tag, uint64_t length, uint64_t start) {
506505void BmffImage::parseTiff (uint32_t root_tag, uint64_t length) {
507506 if (length > 8 ) {
508507 enforce (length - 8 <= io_->size () - io_->tell (), ErrorCode::kerCorruptedMetadata);
509- enforce (length - 8 <= std::numeric_limits<uint64_t >::max (), ErrorCode::kerCorruptedMetadata);
508+ enforce (length - 8 <= std::numeric_limits<size_t >::max (), ErrorCode::kerCorruptedMetadata);
510509 DataBuf data (static_cast <size_t >(length - 8u ));
511510 const size_t bufRead = io_->read (data.data (), data.size ());
512511
@@ -524,8 +523,8 @@ void BmffImage::parseXmp(uint64_t length, uint64_t start) {
524523 enforce (start <= io_->size (), ErrorCode::kerCorruptedMetadata);
525524 enforce (length <= io_->size () - start, ErrorCode::kerCorruptedMetadata);
526525
527- long restore = io_->tell ();
528- io_->seek (static_cast <long >(start), BasicIo::beg);
526+ const size_t restore = io_->tell ();
527+ io_->seek (static_cast <int64_t >(start), BasicIo::beg);
529528
530529 auto lengthSizeT = static_cast <size_t >(length);
531530 DataBuf xmp (lengthSizeT + 1 );
@@ -547,9 +546,8 @@ void BmffImage::parseXmp(uint64_t length, uint64_t start) {
547546void BmffImage::parseCr3Preview (DataBuf& data, std::ostream& out, bool bTrace, uint8_t version, size_t width_offset,
548547 size_t height_offset, size_t size_offset, size_t relative_position) {
549548 // Derived from https://github.com/lclevy/canon_cr3
550- long here = io_->tell ();
551- enforce (here >= 0 && here <= std::numeric_limits<long >::max () - static_cast <long >(relative_position),
552- ErrorCode::kerCorruptedMetadata);
549+ const size_t here = io_->tell ();
550+ enforce (here <= std::numeric_limits<size_t >::max () - relative_position, ErrorCode::kerCorruptedMetadata);
553551 NativePreview nativePreview;
554552 nativePreview.position_ = here + relative_position;
555553 nativePreview.width_ = data.read_uint16 (width_offset, endian_);
@@ -600,8 +598,8 @@ void BmffImage::readMetadata() {
600598 exifID_ = unknownID_;
601599 xmpID_ = unknownID_;
602600
603- long address = 0 ;
604- const auto file_end = static_cast < long >( io_->size () );
601+ uint64_t address = 0 ;
602+ const auto file_end = io_->size ();
605603 while (address < file_end) {
606604 io_->seek (address, BasicIo::beg);
607605 address = boxHandler (std::cout, kpsNone, file_end, 0 );
@@ -635,8 +633,8 @@ void BmffImage::printStructure(std::ostream& out, Exiv2::PrintStructureOption op
635633 openOrThrow ();
636634 IoCloser closer (*io_);
637635
638- long address = 0 ;
639- const auto file_end = static_cast < long >( io_->size () );
636+ uint64_t address = 0 ;
637+ const auto file_end = io_->size ();
640638 while (address < file_end) {
641639 io_->seek (address, BasicIo::beg);
642640 address = boxHandler (out, option, file_end, depth);
@@ -682,7 +680,7 @@ bool isBmffType(BasicIo& iIo, bool advance) {
682680 bool const is_video = (buf[8 ] == ' q' && buf[9 ] == ' t' && buf[10 ] == ' ' && buf[11 ] == ' ' );
683681 bool matched = is_jxl || (is_ftyp && !is_video);
684682 if (!advance || !matched) {
685- iIo.seek (static_cast < long >( 0 ) , BasicIo::beg);
683+ iIo.seek (0 , BasicIo::beg);
686684 }
687685 return matched;
688686}
0 commit comments