fix(yara): use content hash for rule cache invalidation#156
Open
mimran-khan wants to merge 2 commits into
Open
fix(yara): use content hash for rule cache invalidation#156mimran-khan wants to merge 2 commits into
mimran-khan wants to merge 2 commits into
Conversation
_content_hash() previously hashed file paths and sizes only. If a rule file was edited without changing its byte count, the cache would serve stale compiled rules. Switch to hashing actual file content via read_bytes() so any edit invalidates the cache. Fixes NVIDIA#152
keshprad
approved these changes
Jun 22, 2026
Member
|
just added on minor linting fix. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
The YARA rule cache (
_content_hash) invalidated based on file paths and sizes only. If a rule file is edited without changing its byte count (e.g., changing a pattern string to a same-length alternative), the module continues serving stale compiled rules from the previous version.Changes
static_yara.py:_content_hash()now hashes actual file content (read_bytes()) instead of justst_size.test_static_yara.py: 3 new tests inTestContentHashInvalidation— validates that same-size edits produce different hashes, identical content produces stable hashes, and_load_rulesrecompiles after a same-size edit.Before / After
Trade-off
Reading file content is slightly slower than stat-only (~microseconds per rule file). Given that YARA rule directories typically contain <50 small files and compilation itself is the expensive step, this is negligible.
Testing
Fixes #152