aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2011-02-18 18:55:53 +0000
committerlloyd <[email protected]>2011-02-18 18:55:53 +0000
commit17d1cb0d352477bba9ec4e8a237b1cff21cb5d96 (patch)
tree2dc6f767834d7355a85961a9cf01d9d4a4c36897
parentdebeb26a1c2615d7dd61bce535f22133eec38b17 (diff)
Fix PR 142: the zlib filters were not updated in 1.9.11 to use zeroise
instead of clear, so the buffer ended up having size zero, which meant the compression library could never actually do anything, and we would infinite loop. Also add buffer clearing to bzip2, which was missing it entirely.
-rw-r--r--doc/log.txt1
-rw-r--r--src/filters/bzip2/bzip2.cpp24
-rw-r--r--src/filters/zlib/zlib.cpp16
3 files changed, 26 insertions, 15 deletions
diff --git a/doc/log.txt b/doc/log.txt
index 06107928a..d86aba45f 100644
--- a/doc/log.txt
+++ b/doc/log.txt
@@ -2,6 +2,7 @@
* 1.9.14-dev, ????-??-??
- Add support for bcrypt, OpenBSD's password hashing scheme
- Add support for NIST's AES key wrapping algorithm
+ - Fix an infinite loop in zlib filters introduced in 1.9.11 (PR 142)
* 1.9.13, 2011-02-19
- Update Keccak to the round 3 variant
diff --git a/src/filters/bzip2/bzip2.cpp b/src/filters/bzip2/bzip2.cpp
index b166017c3..a291c1173 100644
--- a/src/filters/bzip2/bzip2.cpp
+++ b/src/filters/bzip2/bzip2.cpp
@@ -168,10 +168,14 @@ void Bzip_Compression::flush()
*/
void Bzip_Compression::clear()
{
- if(!bz) return;
- BZ2_bzCompressEnd(&(bz->stream));
- delete bz;
- bz = 0;
+ zeroise(buffer);
+
+ if(bz)
+ {
+ BZ2_bzCompressEnd(&(bz->stream));
+ delete bz;
+ bz = 0;
+ }
}
/*
@@ -278,10 +282,14 @@ void Bzip_Decompression::end_msg()
*/
void Bzip_Decompression::clear()
{
- if(!bz) return;
- BZ2_bzDecompressEnd(&(bz->stream));
- delete bz;
- bz = 0;
+ zeroise(buffer);
+
+ if(bz)
+ {
+ BZ2_bzDecompressEnd(&(bz->stream));
+ delete bz;
+ bz = 0;
+ }
}
}
diff --git a/src/filters/zlib/zlib.cpp b/src/filters/zlib/zlib.cpp
index 30dee0225..0f88b5558 100644
--- a/src/filters/zlib/zlib.cpp
+++ b/src/filters/zlib/zlib.cpp
@@ -138,9 +138,11 @@ void Zlib_Compression::end_msg()
{
zlib->stream.next_out = reinterpret_cast<Bytef*>(buffer.begin());
zlib->stream.avail_out = buffer.size();
+
rc = deflate(&(zlib->stream), Z_FINISH);
send(buffer.begin(), buffer.size() - zlib->stream.avail_out);
}
+
clear();
}
@@ -155,13 +157,13 @@ void Zlib_Compression::flush()
while(true)
{
zlib->stream.avail_out = buffer.size();
-
zlib->stream.next_out = reinterpret_cast<Bytef*>(buffer.begin());
-
deflate(&(zlib->stream), Z_FULL_FLUSH);
send(buffer.begin(), buffer.size() - zlib->stream.avail_out);
- if(zlib->stream.avail_out == buffer.size()) break;
+
+ if(zlib->stream.avail_out == buffer.size())
+ break;
}
}
@@ -170,14 +172,14 @@ void Zlib_Compression::flush()
*/
void Zlib_Compression::clear()
{
+ zeroise(buffer);
+
if(zlib)
{
deflateEnd(&(zlib->stream));
delete zlib;
zlib = 0;
}
-
- buffer.clear();
}
/*
@@ -283,6 +285,8 @@ void Zlib_Decompression::end_msg()
*/
void Zlib_Decompression::clear()
{
+ zeroise(buffer);
+
no_writes = true;
if(zlib)
@@ -291,8 +295,6 @@ void Zlib_Decompression::clear()
delete zlib;
zlib = 0;
}
-
- buffer.clear();
}
}