file_analysis/File: Report overflowing chunks as weird and discard/truncate

This is one level above the Reassembler where we still have information
about the file and source. A weird entry may looks as follows:

    1679759398.237353  ... file_offset_overflow    FXPLGt4SeMmlMKahJc: offset=fffffffffffffff7 len=10      F       zeek    HTTP
This commit is contained in:
Arne Welzel 2023-03-27 15:12:27 +02:00
parent ea80f21e1d
commit fbdc433386

View file

@ -2,6 +2,7 @@
#include "zeek/file_analysis/File.h" #include "zeek/file_analysis/File.h"
#include <limits>
#include <utility> #include <utility>
#include "zeek/Event.h" #include "zeek/Event.h"
@ -431,6 +432,15 @@ void File::DeliverStream(const u_char* data, uint64_t len)
void File::DeliverChunk(const u_char* data, uint64_t len, uint64_t offset) void File::DeliverChunk(const u_char* data, uint64_t len, uint64_t offset)
{ {
if ( std::numeric_limits<uint64_t>::max() - offset < len )
{
reporter->Weird(this, "file_offset_overflow",
zeek::util::fmt("offset=%" PRIx64 " len=%" PRIx64, offset, len),
GetSource().c_str());
len = std::numeric_limits<uint64_t>::max() - offset;
}
// Potentially handle reassembly and deliver to the stream analyzers. // Potentially handle reassembly and deliver to the stream analyzers.
if ( file_reassembler ) if ( file_reassembler )
{ {