#1199 Spit'n'polish on the loops in printStructure(), metadataRead() and doWriteMetadata(). Added tests with even byte count for ICCP and XMP Chunks.

v0.27.3
Robin Mills 9 years ago
parent ed7b20a20e
commit 027b3917ec

@ -182,7 +182,7 @@ namespace Exiv2 {
/* Verify for a VP8X Chunk First before writing in /* Verify for a VP8X Chunk First before writing in
case we have any exif or xmp data, also check case we have any exif or xmp data, also check
for any chunks with alpha frame/layer set */ 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(chunkId.pData_, WEBP_TAG_SIZE);
io_->read(size_buff, WEBP_TAG_SIZE); io_->read(size_buff, WEBP_TAG_SIZE);
long size = Exiv2::getULong(size_buff, littleEndian); long size = Exiv2::getULong(size_buff, littleEndian);
@ -306,13 +306,7 @@ namespace Exiv2 {
} }
io_->seek(12, BasicIo::beg); io_->seek(12, BasicIo::beg);
while ( !io_->eof() && (uint64_t) io_->tell() < filesize) {
while (!io_->eof()) {
uint64_t offset = io_->tell();
if (offset >= filesize) {
break;
}
io_->read(chunkId.pData_, 4); io_->read(chunkId.pData_, 4);
io_->read(size_buff, 4); io_->read(size_buff, 4);
@ -375,19 +369,10 @@ namespace Exiv2 {
throw Error(21); 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 // Encoder required to pad odd sized data with a null byte
if (outIo.tell() % 2) { if (outIo.tell() % 2) {
if (outIo.write(&WEBP_PAD_ODD, 1) != 1) throw Error(21); if (outIo.write(&WEBP_PAD_ODD, 1) != 1) throw Error(21);
} }
if (offset >= filesize) {
break;
}
} }
if (has_exif) { if (has_exif) {
@ -456,13 +441,13 @@ namespace Exiv2 {
} }
io_->seek(0,BasicIo::beg); // rewind io_->seek(0,BasicIo::beg); // rewind
while ( !io_->eof() && (uint64_t) io_->tell() < filesize) {
uint64_t offset = (uint64_t) io_->tell(); uint64_t offset = (uint64_t) io_->tell();
while (!io_->eof() && offset < filesize ) {
byte size_buff[WEBP_TAG_SIZE]; byte size_buff[WEBP_TAG_SIZE];
io_->read(chunkId.pData_, WEBP_TAG_SIZE); io_->read(chunkId.pData_, WEBP_TAG_SIZE);
io_->read(size_buff, WEBP_TAG_SIZE); io_->read(size_buff, WEBP_TAG_SIZE);
long size = Exiv2::getULong(size_buff, littleEndian); 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_); io_->read(payload.pData_, payload.size_);
if ( bPrint ) { if ( bPrint ) {
@ -485,8 +470,7 @@ namespace Exiv2 {
out.write((const char*) payload.pData_,payload.size_); out.write((const char*) payload.pData_,payload.size_);
} }
if ( offset && (payload.size_ % 2)) io_->read(size_buff,1); // skip padding byte on sub-chunks if ( offset && io_->tell() % 2 ) io_->seek(+1, BasicIo::cur); // skip padding byte on sub-chunks
offset = (uint64_t) io_->tell();
} }
} }
} }
@ -525,11 +509,7 @@ namespace Exiv2 {
#endif #endif
chunkId.pData_[4] = '\0' ; chunkId.pData_[4] = '\0' ;
while ( !io_->eof() && (uint64_t) io_->tell() < filesize) {
while ((uint64_t)io_->tell() < filesize) {
if ((uint64_t)(io_->tell() + 2) >= (uint64_t) io_->size()){
break;
}
io_->read(chunkId.pData_, WEBP_TAG_SIZE); io_->read(chunkId.pData_, WEBP_TAG_SIZE);
io_->read(size_buff, WEBP_TAG_SIZE); io_->read(size_buff, WEBP_TAG_SIZE);
long size = Exiv2::getULong(size_buff, littleEndian); long size = Exiv2::getULong(size_buff, littleEndian);

@ -297,6 +297,22 @@ STRUCTURE OF WEBP FILE: exiv2-bug1199.webp
VP8 | 172008 | 598 | .G...*.. .>1..B.!..o.. ......].. VP8 | 172008 | 598 | .G...*.. .>1..B.!..o.. ......]..
EXIF | 12040 | 172614 | II*........................... . EXIF | 12040 | 172614 | II*........................... .
XMP | 2864 | 184662 | <?xpacket begin="..." id="W5M0Mp XMP | 2864 | 184662 | <?xpacket begin="..." id="W5M0Mp
STRUCTURE OF WEBP FILE: exiv2-bug1199.webp
Chunk | Length | Offset | Payload
RIFF | 187526 | 0 | WEBP
VP8X | 10 | 12 | ,........
ICCP | 560 | 30 | ...0ADBE....mntrRGB XYZ ........
VP8 | 172008 | 598 | .G...*.. .>1..B.!..o.. ......]..
EXIF | 12040 | 172614 | II*........................... .
XMP | 2864 | 184662 | <?xpacket begin="..." id="W5M0Mp
STRUCTURE OF WEBP FILE: exiv2-bug1199.webp
Chunk | Length | Offset | Payload
RIFF | 187526 | 0 | WEBP
VP8X | 10 | 12 | ,........
ICCP | 560 | 30 | ...0ADBE....mntrRGB XYZ ........
VP8 | 172008 | 598 | .G...*.. .>1..B.!..o.. ......]..
EXIF | 12040 | 172614 | II*........................... .
XMP | 2864 | 184662 | <?xpacket begin="..." id="W5M0Mp
STRUCTURE OF WEBP FILE: exiv2-bug1199.webp STRUCTURE OF WEBP FILE: exiv2-bug1199.webp
Chunk | Length | Offset | Payload Chunk | Length | Offset | Payload
RIFF | 189580 | 0 | WEBP RIFF | 189580 | 0 | WEBP

@ -35,6 +35,17 @@ source ./functions.source
exiv2 -pS $filename exiv2 -pS $filename
printf "XMP " >&3 printf "XMP " >&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 # copy the XMP from Reagan.tiff to test file
copyTestFile Reagan.tiff copyTestFile Reagan.tiff
exiv2 -pX Reagan.tiff > $xmp_name; exiv2 -pX Reagan.tiff > $xmp_name;

Loading…
Cancel
Save