Fixed an issue in deflate that would cause corruption or fail v1.0.2
authorMichael McMaster <email@michaelmcmaster.name>
Wed, 7 Sep 2011 20:04:11 +0000 (06:04 +1000)
committerMichael McMaster <email@michaelmcmaster.name>
Wed, 7 Sep 2011 20:04:11 +0000 (06:04 +1000)
extract valid files.

NEWS
VERSION
autodeb.sh
debian/changelog
deflate.cc

diff --git a/NEWS b/NEWS
index 967e5e1..85a043f 100644 (file)
--- 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 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.0.1
+1.0.2
index 1dc67d6..b5ee069 100755 (executable)
@@ -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
index 92fa1ba..1d78d64 100644 (file)
@@ -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 <michael@codesrc.com>  Wed, 07 Sep 2011 21:59:18 +1000
+
 libzipper (1.0.1-1) unstable; urgency=low
 
   * Initial release. (Closes: #628118)
index 3fff160..986f6d1 100644 (file)
@@ -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<Bytef*>(&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<Bytef*>(&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)
        {