Improve trend unquarantine performance #2420
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Prior to these changes
trend_unquarantine
was passing the entire sample through a XOR routine before checking the XOR'd file header to determine if it was a quarantined file.For a 100MB sample it was taking ~22 seconds to XOR the file.
By changing the function to only XOR the first 10 bytes of the file (header) before checking the file signature, we remove significant amounts of processing time for what will likely be all samples submitted.
Using the same sample, post-change, the whole
unquarantine
process now only takes 0.770s.Ultimately, I'm not convinced that
trend_unquarantine
works anyway because:.decode
functions.read_trend_tag
returns atuple[int, bytes]
, the tag code and the tag data. When unpacking the original filename tag (tag code 2), it passes the tag data (bytes) into thestr
func, encodes it and then decodes it again. This means the original filename is only ever a string representation of bytes (see below), causing the downstream functions to fail (in my testing, without a proper quarantined file).