Closed BitsOfBinary closed 2 years ago
This is because TimeoutError extends Error, and python checks exceptions in the order you list them. This explains why it works as you expect if you swap the order around in your code. You always want to list most specific to least specific exceptions.
Thanks @wxsBSD, that makes sense!
The documentation says that if a match times out, a
yara.TimeoutError
should be returned: https://yara.readthedocs.io/en/latest/yarapython.html#yara.Rules.matchHowever, when testing this and trying to handle
yara.Error
exceptions separately, these would also catchyara.TimeoutError
exceptions. It looks like this is the case because in the code the following exceptions are all just treated asyara.Error
exceptions instead of the specific error types they should be: https://github.com/VirusTotal/yara-python/blob/4379581cd67b7ae1e5bd83c4a91bfd648277efc1/yara-python.c#L2683-L2685Example code:
If any rule that takes more than 1 second to run times out, a
yara.Error
will be raised instead of ayara.TimeoutError
.This can be fixed by swapping the
except
statements around, but I'm not sure if this is expected behaviour?