From f275ba42be259b90a32a5b7f9399bc175c6e4c4e Mon Sep 17 00:00:00 2001 From: Michael McMaster Date: Thu, 8 Sep 2011 06:04:11 +1000 Subject: [PATCH] Fixed an issue in deflate that would cause corruption or fail extract valid files. --- NEWS | 4 ++++ VERSION | 2 +- autodeb.sh | 4 ++-- debian/changelog | 7 +++++++ deflate.cc | 15 ++++++++++----- 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index 967e5e1..85a043f 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,7 @@ +2011-09-07 Version 1.0.2 + - Fixed a bug in deflate, which caused it to exit prematurely and + report valid files as corrupt. + 2011-05-27 Version 1.0.1 - Removed private classes from doxygen output - Added the zipper utility executable diff --git a/VERSION b/VERSION index 7dea76e..6d7de6e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.1 +1.0.2 diff --git a/autodeb.sh b/autodeb.sh index 1dc67d6..b5ee069 100755 --- a/autodeb.sh +++ b/autodeb.sh @@ -33,10 +33,10 @@ cp -a ${SRC}/debian libzipper-${VERSION} cd libzipper-${VERSION} dpkg-buildpackage -rfakeroot -if ! lintian --color auto --fail-on-warnings -i ${BUILD}/libzipper_1.0.1-1.dsc; then +if ! lintian --color auto --fail-on-warnings -i ${BUILD}/libzipper_1.0.2-1.dsc; then echo "Build failed" exit 1; -elif ! lintian --color auto --fail-on-warnings -i ${BUILD}/libzipper_1.0.1-1_amd64.changes; then +elif ! lintian --color auto --fail-on-warnings -i ${BUILD}/libzipper_1.0.2-1_amd64.changes; then echo "Build failed" exit 1; else diff --git a/debian/changelog b/debian/changelog index 92fa1ba..1d78d64 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +libzipper (1.0.2-1) unstable; urgency=low + + * Fixed a bug in the deflate methods, which would report corrupt data for + valid zip/gzip files. + + -- Michael McMaster Wed, 07 Sep 2011 21:59:18 +1000 + libzipper (1.0.1-1) unstable; urgency=low * Initial release. (Closes: #628118) diff --git a/deflate.cc b/deflate.cc index 3fff160..986f6d1 100644 --- a/deflate.cc +++ b/deflate.cc @@ -94,14 +94,15 @@ zipper::deflate( DeflateDeleter deleter(&stream); stream.next_in = NULL; stream.avail_in = 0; + bool finished(false); zsize_t pos(0); zsize_t end(reader.getSize()); crc = crc32(0, NULL, 0); - while (pos < end) + while (!finished) { - if (stream.avail_in == 0) + if ((stream.avail_in == 0) && (pos < end)) { stream.avail_in = std::min(zsize_t(ChunkSize), end - pos); @@ -116,6 +117,7 @@ zipper::deflate( stream.next_out = reinterpret_cast(&outChunk); stream.avail_out = sizeof(outChunk); + finished = false; zlibErr = deflate(&stream, (pos < end) ? Z_NO_FLUSH : Z_FINISH); if (zlibErr == Z_STREAM_END) @@ -125,6 +127,7 @@ zipper::deflate( assert(!"zlib buffer unexpectedly empty"); std::terminate(); } + finished = true; } else if (zlibErr != Z_OK) { @@ -164,11 +167,15 @@ zipper::inflate( zsize_t pos(readOffset); crc = crc32(0, NULL, 0); - while (pos < readEnd) + while (!finished) { if (stream.avail_in == 0) { stream.avail_in = std::min(zsize_t(ChunkSize), readEnd - pos); + if (stream.avail_in == 0) + { + break; + } reader->readData(pos, stream.avail_in, &inChunk[0]); stream.next_in = reinterpret_cast(&inChunk); pos += stream.avail_in; @@ -193,8 +200,6 @@ zipper::inflate( writer.writeData(writeOffset, bytesToWrite, &outChunk[0]); writeOffset += bytesToWrite; crc = crc32(crc, &outChunk[0], bytesToWrite); - - if (finished) break; } if (!finished) { -- 2.38.5