From 584cc4c0aca4b037fd04f8d37c53757aecf2062f Mon Sep 17 00:00:00 2001 From: Daniel Seither Date: Fri, 28 Aug 2015 16:26:31 +0200 Subject: 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. --- src/lib/compression/compression.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) 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& 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); -- cgit v1.2.3