diff --git a/CHANGELOG.md b/CHANGELOG.md index cd49da66c..f97f2ea93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ - main: suggest --os flag in unsupported OS error message to help users override ELF OS detection @devs6186 #2577 - render: escape sample-controlled strings before passing to Rich to prevent MarkupError @devs6186 #2699 - rules: handle empty or invalid YAML documents gracefully in `Rule.from_yaml` and `get_rules` @devs6186 #2900 +- rules cache: invalidate stale cache format after `_RuleFeatureIndex` schema update to avoid runtime AttributeError in matching - Fixed insecure deserialization vulnerability in YAML loading @0x1622 (#2770) - loader: gracefully handle ELF files with unsupported architectures kamranulhaq2002@gmail.com #2800 - loader: handle SegmentationViolation for malformed ELF files @kami922 #2799 @@ -67,6 +68,7 @@ ### Development - doc: document that default output shows top-level matches only; -v/-vv show nested matches @devs6186 #1410 +- tests: skip `capa2sarif.py` script test when optional dependencies (`sarif_om`, `jschema_to_python`) are not installed - doc: fix typo in usage.md, add documentation links to README @devs6186 #2274 - doc: add table comparing ways to consume capa output (CLI, IDA, Ghidra, dynamic sandbox, web) @devs6186 #2273 - binja: add mypy config for top-level binaryninja module to fix mypy issues @devs6186 #2399 diff --git a/capa/rules/cache.py b/capa/rules/cache.py index f23e61212..3ebf8a976 100644 --- a/capa/rules/cache.py +++ b/capa/rules/cache.py @@ -79,7 +79,7 @@ def get_cache_path(cache_dir: Path, id: CacheIdentifier) -> Path: MAGIC = b"capa" -VERSION = b"\x00\x00\x00\x01" +VERSION = b"\x00\x00\x00\x02" @dataclass @@ -159,7 +159,7 @@ def load_cached_ruleset(cache_dir: Path, rule_contents: list[bytes]) -> Optional try: cache = RuleCache.load(buf) - except AssertionError: + except (AssertionError, EOFError, pickle.UnpicklingError, zlib.error, AttributeError, TypeError, ValueError): logger.debug("rule set cache is invalid: %s", path) # delete the cache that seems to be invalid. path.unlink() diff --git a/tests/test_scripts.py b/tests/test_scripts.py index 20b36f0b9..8a7cbb4a9 100644 --- a/tests/test_scripts.py +++ b/tests/test_scripts.py @@ -18,6 +18,7 @@ import logging import textwrap import subprocess +import importlib.util from pathlib import Path import pytest @@ -25,6 +26,7 @@ logger = logging.getLogger(__name__) CD = Path(__file__).resolve().parent +HAS_CAPA2SARIF_DEPS = importlib.util.find_spec("sarif_om") is not None and importlib.util.find_spec("jschema_to_python") is not None def get_script_path(s: str): @@ -66,6 +68,9 @@ def get_rule_path(): pytest.param( "capa2sarif.py", [Path(__file__).resolve().parent / "data" / "rd" / "Practical Malware Analysis Lab 01-01.dll_.json"], + marks=pytest.mark.skipif( + not HAS_CAPA2SARIF_DEPS, reason="capa2sarif.py requires optional deps: sarif_om and jschema_to_python" + ), ), # testing some variations of linter script pytest.param("lint.py", ["-t", "create directory", get_rules_path()]),