zlib: process inflate Z_STREAM_END as success if no remaining bytes
This commit is contained in:
parent
1f0296a873
commit
5353a22ce0
@ -169,6 +169,18 @@ private:
|
||||
|
||||
#if defined(READFILE_ENABLE_ZLIB)
|
||||
#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 {
|
||||
public:
|
||||
@ -229,11 +241,13 @@ public:
|
||||
while (m_stream.avail_in != 0) {
|
||||
m_stream.next_out = (Bytef*)m_obuf;
|
||||
m_stream.avail_out = m_obs;
|
||||
if ((error = inflate(&m_stream, Z_SYNC_FLUSH)) != Z_OK) {
|
||||
// Note that Z_STREAM_END is also an error here,
|
||||
// because we still have data: something is wrong with
|
||||
// the file.
|
||||
LOGERR("inflate error: " << error << endl);
|
||||
error = inflate(&m_stream, Z_SYNC_FLUSH);
|
||||
if (error != Z_OK &&
|
||||
!(error == Z_STREAM_END && m_stream.avail_in == 0)) {
|
||||
// Note that Z_STREAM_END with avail_in!=0 is an error,
|
||||
// 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) {
|
||||
*reason += " Zlib inflate failed";
|
||||
if (m_stream.msg && *m_stream.msg) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user