zlib: process inflate Z_STREAM_END as success if no remaining bytes

This commit is contained in:
Jean-Francois Dockes 2020-02-28 11:14:39 +01:00
parent 1f0296a873
commit 5353a22ce0

View File

@ -169,6 +169,18 @@ private:
#if defined(READFILE_ENABLE_ZLIB) #if defined(READFILE_ENABLE_ZLIB)
#include <zlib.h> #include <zlib.h>
#include <vector>
static const vector<CharFlags> inflateErrors{
CHARFLAGENTRY(Z_OK),
CHARFLAGENTRY(Z_STREAM_END),
CHARFLAGENTRY(Z_NEED_DICT),
CHARFLAGENTRY(Z_ERRNO),
CHARFLAGENTRY(Z_STREAM_ERROR),
CHARFLAGENTRY(Z_DATA_ERROR),
CHARFLAGENTRY(Z_MEM_ERROR),
CHARFLAGENTRY(Z_BUF_ERROR),
CHARFLAGENTRY(Z_VERSION_ERROR),
};
class GzFilter : public FileScanFilter { class GzFilter : public FileScanFilter {
public: public:
@ -229,11 +241,13 @@ public:
while (m_stream.avail_in != 0) { while (m_stream.avail_in != 0) {
m_stream.next_out = (Bytef*)m_obuf; m_stream.next_out = (Bytef*)m_obuf;
m_stream.avail_out = m_obs; m_stream.avail_out = m_obs;
if ((error = inflate(&m_stream, Z_SYNC_FLUSH)) != Z_OK) { error = inflate(&m_stream, Z_SYNC_FLUSH);
// Note that Z_STREAM_END is also an error here, if (error != Z_OK &&
// because we still have data: something is wrong with !(error == Z_STREAM_END && m_stream.avail_in == 0)) {
// the file. // Note that Z_STREAM_END with avail_in!=0 is an error,
LOGERR("inflate error: " << error << endl); // we still have data: something is wrong with the file.
LOGERR("inflate error: " << valToString(inflateErrors, error)
<< " remaining bytes: " << m_stream.avail_in << endl);
if (reason) { if (reason) {
*reason += " Zlib inflate failed"; *reason += " Zlib inflate failed";
if (m_stream.msg && *m_stream.msg) { if (m_stream.msg && *m_stream.msg) {