aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2015-05-07 01:21:39 +0000
committerlloyd <[email protected]>2015-05-07 01:21:39 +0000
commitf2e1dec033184a603ff1d0e4fa2d3be378b79f8e (patch)
tree09330c0d5babd6844f973ea2b265e6fa44126e38
parente0881a543e39a8fda009fb04d570996db6c4bb11 (diff)
Compression filters were not sizing buffer, causing no input to
be consumed. GH #89
-rw-r--r--src/lib/filters/comp_filter.cpp16
-rw-r--r--src/lib/filters/comp_filter.h11
2 files changed, 16 insertions, 11 deletions
diff --git a/src/lib/filters/comp_filter.cpp b/src/lib/filters/comp_filter.cpp
index 4c5dfac68..76c90d626 100644
--- a/src/lib/filters/comp_filter.cpp
+++ b/src/lib/filters/comp_filter.cpp
@@ -1,6 +1,6 @@
/*
* Filter interface for compression
-* (C) 2014 Jack Lloyd
+* (C) 2014,2015 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
@@ -10,18 +10,19 @@
namespace Botan {
-Compression_Filter::Compression_Filter(const std::string& type, size_t level) :
- Compression_Decompression_Filter(make_compressor(type, level))
+Compression_Filter::Compression_Filter(const std::string& type, size_t level, size_t bs) :
+ Compression_Decompression_Filter(make_compressor(type, level), bs)
{
}
-Decompression_Filter::Decompression_Filter(const std::string& type) :
- Compression_Decompression_Filter(make_decompressor(type))
+Decompression_Filter::Decompression_Filter(const std::string& type, size_t bs) :
+ Compression_Decompression_Filter(make_decompressor(type), bs)
{
}
-Compression_Decompression_Filter::Compression_Decompression_Filter(Transform* transform)
+Compression_Decompression_Filter::Compression_Decompression_Filter(Transform* transform, size_t bs)
{
+ 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");
@@ -41,7 +42,8 @@ void Compression_Decompression_Filter::write(const byte input[], size_t input_le
{
while(input_length)
{
- const size_t take = std::min<size_t>({4096, m_buffer.capacity(), input_length});
+ const size_t take = std::min(m_buffer.size(), input_length);
+ BOTAN_ASSERT(take > 0, "Consumed something");
m_buffer.assign(input, input + take);
m_transform->update(m_buffer);
diff --git a/src/lib/filters/comp_filter.h b/src/lib/filters/comp_filter.h
index 2284d8963..503f25102 100644
--- a/src/lib/filters/comp_filter.h
+++ b/src/lib/filters/comp_filter.h
@@ -1,6 +1,6 @@
/*
* Filter interface for compression
-* (C) 2014 Jack Lloyd
+* (C) 2014,2015 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
@@ -28,7 +28,7 @@ class BOTAN_DLL Compression_Decompression_Filter : public Filter
std::string name() const override;
protected:
- Compression_Decompression_Filter(Transform* t);
+ Compression_Decompression_Filter(Transform* t, size_t bs);
void flush();
private:
@@ -39,7 +39,9 @@ class BOTAN_DLL Compression_Decompression_Filter : public Filter
class BOTAN_DLL Compression_Filter : public Compression_Decompression_Filter
{
public:
- Compression_Filter(const std::string& type, size_t level); // compression
+ Compression_Filter(const std::string& type,
+ size_t compression_level,
+ size_t buffer_size = 4096);
using Compression_Decompression_Filter::flush;
};
@@ -47,7 +49,8 @@ class BOTAN_DLL Compression_Filter : public Compression_Decompression_Filter
class Decompression_Filter : public Compression_Decompression_Filter
{
public:
- Decompression_Filter(const std::string& type);
+ Decompression_Filter(const std::string& type,
+ size_t buffer_size = 4096);
};
}