From 6a51315c4bea471a5093b0ce621643b7012a7d8c Mon Sep 17 00:00:00 2001 From: "eric.cornelius" Date: Sat, 16 May 2015 11:55:20 +0000 Subject: Correct buffering logic in compression filter. GH issue #93 pull #95 Found and fixed by Eric Cornelius --- src/lib/filters/comp_filter.cpp | 6 +++--- src/lib/filters/comp_filter.h | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lib/filters/comp_filter.cpp b/src/lib/filters/comp_filter.cpp index 76c90d626..61ac16f38 100644 --- a/src/lib/filters/comp_filter.cpp +++ b/src/lib/filters/comp_filter.cpp @@ -20,9 +20,9 @@ Decompression_Filter::Decompression_Filter(const std::string& type, size_t bs) : { } -Compression_Decompression_Filter::Compression_Decompression_Filter(Transform* transform, size_t bs) +Compression_Decompression_Filter::Compression_Decompression_Filter(Transform* transform, size_t bs) : + m_buffersize(std::max(256, bs)), m_buffer(m_buffersize) { - m_buffer.resize(std::min(256, bs)); m_transform.reset(dynamic_cast(transform)); if(!m_transform) throw std::invalid_argument("Transform " + transform->name() + " is not a compressor"); @@ -42,7 +42,7 @@ void Compression_Decompression_Filter::write(const byte input[], size_t input_le { while(input_length) { - const size_t take = std::min(m_buffer.size(), input_length); + const size_t take = std::min(m_buffersize, input_length); BOTAN_ASSERT(take > 0, "Consumed something"); m_buffer.assign(input, input + take); diff --git a/src/lib/filters/comp_filter.h b/src/lib/filters/comp_filter.h index 503f25102..59d6f7185 100644 --- a/src/lib/filters/comp_filter.h +++ b/src/lib/filters/comp_filter.h @@ -33,6 +33,7 @@ class BOTAN_DLL Compression_Decompression_Filter : public Filter void flush(); private: std::unique_ptr m_transform; + std::size_t m_buffersize; secure_vector m_buffer; }; -- cgit v1.2.3