mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Speed up ChunkCount validity check
When counting chunks for the purpose of a Valid check, only count up to chunk_count_limit + 1 chunks. This speeds up the skipping of the 70,000 chunk test file considerably. Before: Processed 1 inputs in 0.025517s After: Processed 1 inputs in 0.000620s
This commit is contained in:
parent
7d98d816d8
commit
6aa6eea7bc
2 changed files with 4 additions and 4 deletions
|
@ -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 ( ChunkCount(chunk_count_limit + 1) > 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 && (chunk_count_limit == 0 || chunks < chunk_count_limit) )
|
||||||
{
|
{
|
||||||
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);
|
||||||
|
|
|
@ -49,7 +49,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* @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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the next chunk to deliver, if one could be extracted
|
* @return the next chunk to deliver, if one could be extracted
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue