mirror of
https://github.com/tstack/lnav
synced 2024-11-15 18:13:10 +00:00
Don't try to read concatenated gzip streams
Don't try to continue reading the next stream of a concatenated gzip file. The next stream may be CRC noise or other garbage. Maybe in the future we should look for a gzip header in the following bytes of the stream and try to decode from there. But it's not clear that anyone ever uses this supposed gzip feature anyway. Let's just end the stream when we reach EOS. Also, if the stream fails to init, let's leave it closed instead of throwing an error no one is likely to catch. Log the error msg from zlib if one is provided.
This commit is contained in:
parent
2a7db9b257
commit
1d127053e9
@ -152,27 +152,9 @@ void line_buffer::gz_indexed::init_stream()
|
|||||||
this->strm.avail_out = 0;
|
this->strm.avail_out = 0;
|
||||||
int rc = inflateInit2(&strm, GZ_HEADER_MODE);
|
int rc = inflateInit2(&strm, GZ_HEADER_MODE);
|
||||||
if (rc != Z_OK) {
|
if (rc != Z_OK) {
|
||||||
throw(rc); // FIXME: exception wrapper
|
log_error(" inflateInit2: %d %s", (int)rc, this->strm.msg ? this->strm.msg : "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void line_buffer::gz_indexed::continue_stream()
|
|
||||||
{
|
|
||||||
// Save our position and output buffer
|
|
||||||
auto total_in = this->strm.total_in;
|
|
||||||
auto total_out = this->strm.total_out;
|
|
||||||
auto avail_out = this->strm.avail_out;
|
|
||||||
auto next_out = this->strm.next_out;
|
|
||||||
|
|
||||||
init_stream();
|
|
||||||
|
|
||||||
// Restore position and output buffer
|
|
||||||
this->strm.total_in = total_in;
|
|
||||||
this->strm.total_out = total_out;
|
|
||||||
this->strm.avail_out = avail_out;
|
|
||||||
this->strm.next_out = next_out;
|
|
||||||
}
|
|
||||||
|
|
||||||
void line_buffer::gz_indexed::open(int fd)
|
void line_buffer::gz_indexed::open(int fd)
|
||||||
{
|
{
|
||||||
this->close();
|
this->close();
|
||||||
@ -204,11 +186,10 @@ int line_buffer::gz_indexed::stream_data(void * buf, size_t size)
|
|||||||
? Z_SYNC_FLUSH : Z_BLOCK;
|
? Z_SYNC_FLUSH : Z_BLOCK;
|
||||||
auto err = inflate(&this->strm, flush);
|
auto err = inflate(&this->strm, flush);
|
||||||
if (err == Z_STREAM_END) {
|
if (err == Z_STREAM_END) {
|
||||||
// Reached end of stream; re-init for a possible subsequent stream
|
break;
|
||||||
continue_stream();
|
|
||||||
} else if (err != Z_OK) {
|
} else if (err != Z_OK) {
|
||||||
log_error(" inflate-error: %d", (int)err);
|
log_error(" inflate-error: %d %s", (int)err, this->strm.msg ? this->strm.msg : "");
|
||||||
throw error(err); // FIXME: exception wrapper
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->strm.total_in >= last + SYNCPOINT_SIZE &&
|
if (this->strm.total_in >= last + SYNCPOINT_SIZE &&
|
||||||
|
@ -104,7 +104,6 @@ public:
|
|||||||
|
|
||||||
void close();
|
void close();
|
||||||
void init_stream();
|
void init_stream();
|
||||||
void continue_stream();
|
|
||||||
void open(int fd);
|
void open(int fd);
|
||||||
int stream_data(void * buf, size_t size);
|
int stream_data(void * buf, size_t size);
|
||||||
void seek(off_t offset);
|
void seek(off_t offset);
|
||||||
|
Loading…
Reference in New Issue
Block a user