diff --git a/src/webpimage.cpp b/src/webpimage.cpp index 4dc24437..c6a4c2b4 100644 --- a/src/webpimage.cpp +++ b/src/webpimage.cpp @@ -182,7 +182,7 @@ namespace Exiv2 { /* Verify for a VP8X Chunk First before writing in case we have any exif or xmp data, also check for any chunks with alpha frame/layer set */ - while (!io_->eof()) { + while ( !io_->eof() && (uint64_t) io_->tell() < filesize) { io_->read(chunkId.pData_, WEBP_TAG_SIZE); io_->read(size_buff, WEBP_TAG_SIZE); long size = Exiv2::getULong(size_buff, littleEndian); @@ -306,13 +306,7 @@ namespace Exiv2 { } io_->seek(12, BasicIo::beg); - - while (!io_->eof()) { - uint64_t offset = io_->tell(); - if (offset >= filesize) { - break; - } - + while ( !io_->eof() && (uint64_t) io_->tell() < filesize) { io_->read(chunkId.pData_, 4); io_->read(size_buff, 4); @@ -375,19 +369,10 @@ namespace Exiv2 { throw Error(21); } - if (outIo.tell() % 2) { // pad - if (outIo.write(&WEBP_PAD_ODD, 1) != 1) throw Error(21); - } - offset = io_->tell(); - // Encoder required to pad odd sized data with a null byte if (outIo.tell() % 2) { if (outIo.write(&WEBP_PAD_ODD, 1) != 1) throw Error(21); } - - if (offset >= filesize) { - break; - } } if (has_exif) { @@ -456,13 +441,13 @@ namespace Exiv2 { } io_->seek(0,BasicIo::beg); // rewind - uint64_t offset = (uint64_t) io_->tell(); - while (!io_->eof() && offset < filesize ) { + while ( !io_->eof() && (uint64_t) io_->tell() < filesize) { + uint64_t offset = (uint64_t) io_->tell(); byte size_buff[WEBP_TAG_SIZE]; io_->read(chunkId.pData_, WEBP_TAG_SIZE); io_->read(size_buff, WEBP_TAG_SIZE); long size = Exiv2::getULong(size_buff, littleEndian); - DataBuf payload(offset?size:WEBP_TAG_SIZE); // header is a bit of a dummy! (different from other chunks) + DataBuf payload(offset?size:WEBP_TAG_SIZE); // header is different from chunks io_->read(payload.pData_, payload.size_); if ( bPrint ) { @@ -485,8 +470,7 @@ namespace Exiv2 { out.write((const char*) payload.pData_,payload.size_); } - if ( offset && (payload.size_ % 2)) io_->read(size_buff,1); // skip padding byte on sub-chunks - offset = (uint64_t) io_->tell(); + if ( offset && io_->tell() % 2 ) io_->seek(+1, BasicIo::cur); // skip padding byte on sub-chunks } } } @@ -518,18 +502,14 @@ namespace Exiv2 { { DataBuf chunkId(5); byte size_buff[WEBP_TAG_SIZE]; - bool has_canvas_data = false; + bool has_canvas_data = false; #ifdef DEBUG std::cout << "Reading metadata" << std::endl; #endif chunkId.pData_[4] = '\0' ; - - while ((uint64_t)io_->tell() < filesize) { - if ((uint64_t)(io_->tell() + 2) >= (uint64_t) io_->size()){ - break; - } + while ( !io_->eof() && (uint64_t) io_->tell() < filesize) { io_->read(chunkId.pData_, WEBP_TAG_SIZE); io_->read(size_buff, WEBP_TAG_SIZE); long size = Exiv2::getULong(size_buff, littleEndian); diff --git a/test/data/webp-test.out b/test/data/webp-test.out index 604aad51..024fd72e 100644 --- a/test/data/webp-test.out +++ b/test/data/webp-test.out @@ -297,6 +297,22 @@ STRUCTURE OF WEBP FILE: exiv2-bug1199.webp VP8 | 172008 | 598 | .G...*.. .>1..B.!..o.. ......].. EXIF | 12040 | 172614 | II*........................... . XMP | 2864 | 184662 | 1..B.!..o.. ......].. + EXIF | 12040 | 172614 | II*........................... . + XMP | 2864 | 184662 | 1..B.!..o.. ......].. + EXIF | 12040 | 172614 | II*........................... . + XMP | 2864 | 184662 | &3 + # copy the XMP from the test file + copyTestFile $filename + exiv2 -pX $filename > $xmp_name; + exiv2 -ea --force $filename + + copyTestFile $filename + exiv2 -pS $filename + exiv2 -iX $filename + exiv2 -pS $filename + exiv2 -ix $filename + # copy the XMP from Reagan.tiff to test file copyTestFile Reagan.tiff exiv2 -pX Reagan.tiff > $xmp_name; @@ -61,12 +72,12 @@ source ./functions.source exiv2 -pS $filename printf "EXIF " >&3 - copyTestFile exiv2-bug937.jpg $filename - exiv2 --force -ea $filename - copyTestFile $filename - exiv2 -pS $filename - exiv2 -ie $filename - exiv2 -pS $filename + copyTestFile exiv2-bug937.jpg $filename + exiv2 --force -ea $filename + copyTestFile $filename + exiv2 -pS $filename + exiv2 -ie $filename + exiv2 -pS $filename ) 3>&1 > $results 2>&1