Merge remote-tracking branch 'origin/topic/jazoff/fuzz-size-limit-speedup'

- Factored check into more descriptive function: ExceedsChunkLimit()

* origin/topic/jazoff/fuzz-size-limit-speedup:
  Speed up ChunkCount validity check
This commit is contained in:
Jon Siwek 2020-05-21 11:35:30 -07:00
commit 05f829c727
4 changed files with 18 additions and 5 deletions

View file

@ -1,4 +1,8 @@
3.2.0-dev.557 | 2020-05-21 11:41:12 -0700
* Speed up FuzzBuffer ChunkCount validity check (Justin Azoff, Corelight)
3.2.0-dev.555 | 2020-05-20 11:19:08 -0700 3.2.0-dev.555 | 2020-05-20 11:19:08 -0700
* Disable output of Reporter messages to stderr in fuzz targets (Jon Siwek, Corelight) * Disable output of Reporter messages to stderr in fuzz targets (Jon Siwek, Corelight)

View file

@ -1 +1 @@
3.2.0-dev.555 3.2.0-dev.557

View file

@ -14,18 +14,18 @@ bool zeek::detail::FuzzBuffer::Valid(int chunk_count_limit) const
if ( memcmp(begin, PKT_MAGIC, PKT_MAGIC_LEN) != 0) if ( memcmp(begin, PKT_MAGIC, PKT_MAGIC_LEN) != 0)
return false; return false;
if ( ChunkCount() > chunk_count_limit ) if ( ExceedsChunkLimit(chunk_count_limit) )
return false; return false;
return true; return true;
} }
int zeek::detail::FuzzBuffer::ChunkCount() const int zeek::detail::FuzzBuffer::ChunkCount(int chunk_count_limit) const
{ {
auto pos = begin; auto pos = begin;
int chunks = 0; int chunks = 0;
while ( pos < end ) while ( pos < end && (chunks < chunk_count_limit || chunk_count_limit == 0) )
{ {
pos = (const unsigned char*)memmem(pos, end - pos, pos = (const unsigned char*)memmem(pos, end - pos,
PKT_MAGIC, PKT_MAGIC_LEN); PKT_MAGIC, PKT_MAGIC_LEN);

View file

@ -47,9 +47,18 @@ public:
bool Valid(int chunk_count_limit = MAX_CHUNK_COUNT) const; bool Valid(int chunk_count_limit = MAX_CHUNK_COUNT) const;
/** /**
* @param chunk_count_limit Number of chunks to stop counting at (zero
* means "never stop").
* @return the number of chunks in the fuzz buffer object * @return the number of chunks in the fuzz buffer object
*/ */
int ChunkCount() const; int ChunkCount(int chunk_count_limit = 0) const;
/**
* @param Maximum number of chunks to permit the FuzzBuffer to have.
* @return Whether the FuzzBuffer exceeds the desired chunk count limit.
*/
bool ExceedsChunkLimit(int chunk_count_limit) const
{ return ChunkCount(chunk_count_limit + 1) > chunk_count_limit; }
/** /**
* @return the next chunk to deliver, if one could be extracted * @return the next chunk to deliver, if one could be extracted