Skip to content

Commit 9ec53dc

Browse files
committed
TCP input: add limit for maximum buffer size in Lz4 decoder
1 parent 85009a8 commit 9ec53dc

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

‎src/plugins/input/tcp/src/Lz4Decoder.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@
2525
#include "DecodeBuffer.hpp" // DecodeBuffer
2626
#include "read_until_n.hpp" // read_until_n
2727

28+
// This is the maximum size of the buffer used for receiving compressed data and then decompressing it.
29+
//
30+
// This value should always be enough with the current implementation, as messages are decoded one by
31+
// one and a message cannot exceed 64kB due to uint16 limitation.
32+
//
33+
static constexpr size_t LZ4_MAX_BUFFER_SIZE = 256 * 1024;
34+
2835
namespace tcp_in {
2936

3037
struct __attribute__((__packed__)) ipfix_compress_header {
@@ -124,6 +131,9 @@ bool Lz4Decoder::read_start_header() {
124131
// Get the ring buffer size from the header.
125132
auto hdr = reinterpret_cast<ipfix_start_compress_header *>(m_compressed.data());
126133
auto new_buffer_size = ntohl(hdr->buffer_size);
134+
if (new_buffer_size == 0 || new_buffer_size > LZ4_MAX_BUFFER_SIZE) {
135+
throw std::runtime_error("LZ4 Decoder: invalid buffer size");
136+
}
127137

128138
// The start header is not part of the message that should be decompressed.
129139
m_compressed.clear();

0 commit comments

Comments
 (0)