Fix crash and bad small file handling in readfile.cpp

This commit is contained in:
Jean-Francois Dockes 2018-12-26 15:51:43 +01:00
parent f8a9d9cf7b
commit 094a119538

View File

@ -178,15 +178,12 @@ public:
m_stream.avail_in = cnt; m_stream.avail_in = cnt;
if (m_initdone == false) { if (m_initdone == false) {
m_initdone = true; // We do not support a first read cnt < 2. This quite
// We do not support a first read cnt < 2. We probably should. // probably can't happen with a compressed file (size>2)
if (cnt < 2) { // except if we're reading a tty which is improbable. So
if (reason) // assume this is a regular file.
*reason += "GzFilter: first data count < 2";
return false;
}
const unsigned char *ubuf = (const unsigned char *)buf; const unsigned char *ubuf = (const unsigned char *)buf;
if (ubuf[0] != 0x1f || ubuf[1] != 0x8b) { if ((cnt < 2) || ubuf[0] != 0x1f || ubuf[1] != 0x8b) {
LOGDEB1("GzFilter::data: not gzip. out() is " << out() << "\n"); LOGDEB1("GzFilter::data: not gzip. out() is " << out() << "\n");
pop(); pop();
if (out()) { if (out()) {
@ -210,6 +207,7 @@ public:
} }
return false; return false;
} }
m_initdone = true;
} }
while (m_stream.avail_in != 0) { while (m_stream.avail_in != 0) {