aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreric.cornelius <[email protected]>2015-05-16 11:55:20 +0000
committerlloyd <[email protected]>2015-05-16 11:55:20 +0000
commit6a51315c4bea471a5093b0ce621643b7012a7d8c (patch)
treee764d6fc24c33d81b1b296f67be606c6b894ec4c
parenta4e88fa2610da732ea1125b1ed970baed6d286bb (diff)
Correct buffering logic in compression filter. GH issue #93 pull #95
Found and fixed by Eric Cornelius <[email protected]>
-rw-r--r--src/lib/filters/comp_filter.cpp6
-rw-r--r--src/lib/filters/comp_filter.h1
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<size_t>(256, bs)), m_buffer(m_buffersize)
{
- m_buffer.resize(std::min<size_t>(256, bs));
m_transform.reset(dynamic_cast<Compressor_Transform*>(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<Compressor_Transform> m_transform;
+ std::size_t m_buffersize;
secure_vector<byte> m_buffer;
};