This fixes strange decompression errors

It smells like memory corruption, so this probably only works around the
problem.
This commit is contained in:
Lubos Dolezel 2017-03-24 23:36:44 +01:00
parent 3261d4dfbd
commit b1bf40b04d
2 changed files with 14 additions and 11 deletions

View File

@ -16,13 +16,16 @@ PbzxReader::PbzxReader(std::shared_ptr<Reader> reader)
m_lastFlags = be64toh(m_lastFlags);
m_compressedOffset = 12;
if (lzma_stream_decoder(&m_strm, UINT64_MAX, LZMA_CONCATENATED) != LZMA_OK)
m_strm = new lzma_stream;
memset(m_strm, 0, sizeof(*m_strm));
if (lzma_stream_decoder(m_strm, UINT64_MAX, LZMA_CONCATENATED) != LZMA_OK)
throw std::runtime_error("lzma init error");
}
PbzxReader::~PbzxReader()
{
lzma_end(&m_strm);
lzma_end(m_strm);
}
bool PbzxReader::isPbzx(std::shared_ptr<Reader> reader)
@ -44,14 +47,14 @@ int32_t PbzxReader::read(void* buf, int32_t count, uint64_t offset)
uint32_t done = 0;
m_strm.next_out = static_cast<uint8_t*>(buf);
m_strm.avail_out = count;
m_strm->next_out = static_cast<uint8_t*>(buf);
m_strm->avail_out = count;
while (m_strm.avail_out > 0)
while (m_strm->avail_out > 0)
{
int status;
if (!m_strm.avail_in)
if (!m_strm->avail_in)
{
if (!m_remainingRunLength)
{
@ -79,16 +82,16 @@ int32_t PbzxReader::read(void* buf, int32_t count, uint64_t offset)
m_compressedOffset += rd;
m_remainingRunLength -= rd;
m_strm.next_in = reinterpret_cast<const uint8_t*>(m_buffer);
m_strm.avail_in = rd;
m_strm->next_in = reinterpret_cast<const uint8_t*>(m_buffer);
m_strm->avail_in = rd;
}
status = lzma_code(&m_strm, LZMA_RUN);
status = lzma_code(m_strm, LZMA_RUN);
if (status != LZMA_OK)
throw std::runtime_error("lzma decompression error");
}
done = count - m_strm.avail_out;
done = count - m_strm->avail_out;
m_lastReadEnd += done;
return done;

View File

@ -13,7 +13,7 @@ public:
static bool isPbzx(std::shared_ptr<Reader> reader);
private:
lzma_stream m_strm = LZMA_STREAM_INIT;
lzma_stream* m_strm;
uint64_t m_remainingRunLength = 0, m_lastFlags;
};