summaryrefslogtreecommitdiff
path: root/zinflate.cpp
diff options
context:
space:
mode:
authorrocksonhead <30463961+rocksonhead@users.noreply.github.com>2018-03-25 00:27:03 +0000
committerJeffrey Walton <noloader@gmail.com>2018-03-24 20:27:03 -0400
commitb0f71705955698cf1e0d1101dbe6430566b70b63 (patch)
tree2fc87d5492dbfbd13c285ff5ee0fac80af422397 /zinflate.cpp
parentb42d728628fbfed9330aaa27eeb9d522a1307a6c (diff)
downloadcryptopp-git-b0f71705955698cf1e0d1101dbe6430566b70b63.tar.gz
Fix calling multiple ZlibDecompressor in parallel causes adler32 checksum failure (GH #596, #600)
Diffstat (limited to 'zinflate.cpp')
-rw-r--r--zinflate.cpp60
1 files changed, 35 insertions, 25 deletions
diff --git a/zinflate.cpp b/zinflate.cpp
index 9a41462f..4df27c9d 100644
--- a/zinflate.cpp
+++ b/zinflate.cpp
@@ -612,41 +612,51 @@ void Inflator::FlushOutput()
}
}
-struct NewFixedLiteralDecoder
+void Inflator::CreateFixedLiteralDecoder()
{
- HuffmanDecoder * operator()() const
- {
- unsigned int codeLengths[288];
- std::fill(codeLengths + 0, codeLengths + 144, 8);
- std::fill(codeLengths + 144, codeLengths + 256, 9);
- std::fill(codeLengths + 256, codeLengths + 280, 7);
- std::fill(codeLengths + 280, codeLengths + 288, 8);
- member_ptr<HuffmanDecoder> pDecoder(new HuffmanDecoder);
- pDecoder->Initialize(codeLengths, 288);
- return pDecoder.release();
- }
+ unsigned int codeLengths[288];
+ std::fill(codeLengths + 0, codeLengths + 144, 8);
+ std::fill(codeLengths + 144, codeLengths + 256, 9);
+ std::fill(codeLengths + 256, codeLengths + 280, 7);
+ std::fill(codeLengths + 280, codeLengths + 288, 8);
+ m_fixedLiteralDecoder.reset(new HuffmanDecoder);
+ m_fixedLiteralDecoder->Initialize(codeLengths, 288);
};
-struct NewFixedDistanceDecoder
+void Inflator::CreateFixedDistanceDecoder()
{
- HuffmanDecoder * operator()() const
- {
- unsigned int codeLengths[32];
- std::fill(codeLengths + 0, codeLengths + 32, 5);
- member_ptr<HuffmanDecoder> pDecoder(new HuffmanDecoder);
- pDecoder->Initialize(codeLengths, 32);
- return pDecoder.release();
- }
+ unsigned int codeLengths[32];
+ std::fill(codeLengths + 0, codeLengths + 32, 5);
+ m_fixedDistanceDecoder.reset(new HuffmanDecoder);
+ m_fixedDistanceDecoder->Initialize(codeLengths, 32);
};
-const HuffmanDecoder& Inflator::GetLiteralDecoder() const
+const HuffmanDecoder& Inflator::GetLiteralDecoder()
{
- return m_blockType == 1 ? Singleton<HuffmanDecoder, NewFixedLiteralDecoder>().Ref() : m_dynamicLiteralDecoder;
+ if (m_blockType == 1)
+ {
+ if (m_fixedLiteralDecoder.get() == NULLPTR)
+ CreateFixedLiteralDecoder();
+ return *m_fixedLiteralDecoder;
+ }
+ else
+ {
+ return m_dynamicLiteralDecoder;
+ }
}
-const HuffmanDecoder& Inflator::GetDistanceDecoder() const
+const HuffmanDecoder& Inflator::GetDistanceDecoder()
{
- return m_blockType == 1 ? Singleton<HuffmanDecoder, NewFixedDistanceDecoder>().Ref() : m_dynamicDistanceDecoder;
+ if (m_blockType == 1)
+ {
+ if (m_fixedDistanceDecoder.get() == NULLPTR)
+ CreateFixedDistanceDecoder();
+ return *m_fixedDistanceDecoder;
+ }
+ else
+ {
+ return m_dynamicDistanceDecoder;
+ }
}
NAMESPACE_END