aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDaniel Seither <[email protected]>2015-08-28 16:26:31 +0200
committerDaniel Seither <[email protected]>2015-08-28 16:26:31 +0200
commit584cc4c0aca4b037fd04f8d37c53757aecf2062f (patch)
treed9ce67321fa66f3ff21bcd81f908daee09762b0f /src
parent294b66f579b6892fc60a88c27790c9da9da8c590 (diff)
Compression: Fix zlib failure on compression of empty input
zlib treats a nullptr output buffer as an error. This commit fixes the failing compression tests.
Diffstat (limited to 'src')
-rw-r--r--src/lib/compression/compression.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/lib/compression/compression.cpp b/src/lib/compression/compression.cpp
index 22ee700b6..ddbcd7cec 100644
--- a/src/lib/compression/compression.cpp
+++ b/src/lib/compression/compression.cpp
@@ -104,6 +104,14 @@ void Stream_Compression::process(secure_vector<byte>& buf, size_t offset, u32bit
if(m_buffer.size() < buf.size() + offset)
m_buffer.resize(buf.size() + offset);
+ // If the output buffer has zero length, .data() might return nullptr. This would
+ // make some compression algorithms (notably those provided by zlib) fail.
+ // Any small positive value works fine, but we choose 32 as it is the smallest power
+ // of two that is large enough to hold all the headers and trailers of the common
+ // formats, preventing further resizings to make room for output data.
+ if(m_buffer.size() == 0)
+ m_buffer.resize(32);
+
m_stream->next_in(buf.data() + offset, buf.size() - offset);
m_stream->next_out(m_buffer.data() + offset, m_buffer.size() - offset);