diff --git a/src/plugins/input/tcp/src/LZ4Decoder.cpp b/src/plugins/input/tcp/src/LZ4Decoder.cpp index fe3c9980..7d6e7ebb 100644 --- a/src/plugins/input/tcp/src/LZ4Decoder.cpp +++ b/src/plugins/input/tcp/src/LZ4Decoder.cpp @@ -30,17 +30,13 @@ namespace tcp_in { using namespace std; struct __attribute__((__packed__)) ipfix_compress_header { - uint32_t magic; uint16_t decompressed_size; uint16_t compressed_size; }; struct __attribute__((__packed__)) ipfix_start_compress_header { uint32_t magic; - uint32_t zeros; uint32_t buffer_size; - uint16_t decompressed_size; - uint16_t compressed_size; }; Lz4Decoder::Lz4Decoder(int fd) : @@ -53,6 +49,7 @@ Lz4Decoder::Lz4Decoder(int fd) : m_compressed_size(0), m_decompressed_size(0) { + uint32_t magic = 0; if (!m_decoder) { throw runtime_error("LZ4 Decoder: Failed to create stream decoder"); } @@ -91,15 +88,17 @@ bool Lz4Decoder::read_header() { return false; } - auto hdr = reinterpret_cast(m_compressed.data()); - if (hdr->compressed_size == 0 && hdr->decompressed_size == 0) { - return read_start_header(); + if (m_decompressed.size() == 0) { + if (!read_start_header()) { + return false; + } } if (!read_until_n(CH_SIZE)) { return false; } + auto hdr = reinterpret_cast(m_compressed.data()); m_compressed_size = ntohs(hdr->compressed_size); m_decompressed_size = ntohs(hdr->decompressed_size); @@ -118,9 +117,6 @@ bool Lz4Decoder::read_start_header() { auto hdr = reinterpret_cast(m_compressed.data()); auto new_buffer_size = ntohl(hdr->buffer_size); - m_compressed_size = ntohs(hdr->compressed_size); - m_decompressed_size = ntohs(hdr->decompressed_size); - m_compressed.clear(); reset_stream(new_buffer_size);