Skip to content

[pull] master from kevoreilly:master#500

Merged
pull[bot] merged 17 commits into
threatcode:masterfrom
kevoreilly:master
Jul 8, 2026
Merged

[pull] master from kevoreilly:master#500
pull[bot] merged 17 commits into
threatcode:masterfrom
kevoreilly:master

Conversation

@pull

@pull pull Bot commented Jul 8, 2026

Copy link
Copy Markdown

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.4)

Can you help keep this open source service alive? 💖 Please sponsor : )

wmetcalf and others added 17 commits May 12, 2026 11:15
… YARA init guard

- clamav.py: Add prefetch_clamav() using ThreadPoolExecutor to fan out
  ALLMATCHSCAN calls in parallel before the sequential per-file loop.
  Reduces ClamAV wall-clock from sum(scans) to slowest single scan.
  Adds module-level _CLAMAV_CACHE + _CACHE_LOCK for per-task caching.

- CAPE.py: Call prefetch_clamav() with all target + dropped + procdump
  paths before the per-file processing loop; clear cache on exit.

- file_extra_info.py: Share a module-level pebble.ProcessPool singleton
  (get_extractor_pool()) instead of creating/destroying one per file.
  Also re-run PortableExecutable() when pe.digital_signers is empty so
  previously-analysed files get the cert data filled in on reprocess.

- parse_pe.py: get_actual_checksum() returns None when the PE reports
  checksum=0, skipping the expensive O(file_size) recompute. Fix
  backend.load_der_pkcs7_certificates → pkcs7.load_der_pkcs7_certificates
  for cryptography ≥ 40.x (old method removed from Backend).

- objects.py: Add idempotency guard to File.init_yara() so repeated
  calls in multi-worker environments don't reload rules unnecessarily.

- process.py: Eagerly call File.init_yara() in init_worker() so YARA
  rules are loaded once at worker startup rather than on first task.
…traction

- process.py: Replace h.close()/removeHandler()/addHandler() calls with
  direct log.handlers[:] = [] and log.handlers.append() to avoid acquiring
  logging locks in child processes after fork() (deadlock risk if parent
  held the lock at fork time).

- file_extra_info.py: Only re-run PortableExecutable cert extraction when
  DigiSig.json confirms the file is signed (aux_signers non-empty). Without
  this guard, every unsigned PE would trigger a redundant re-parse on
  reprocess.
Setting it inside the HAVE_YARA try block marked init complete after the first
successful category (binaries), so any concurrent or subsequent init_yara()
call would short-circuit before CAPE was reached — KeyError: CAPE in get_yara.
Also fixes YARA_X path which never set yara_initialized at all.
…est-state leak

The new init_yara() idempotency guard exposed a latent cross-test pollution bug that fails
tests/test_yara.py::test_get_yaras in the full suite (passes in isolation):

  - tests/test_objects.py::test_get_yara replaces the class-level File.yara_rules with a single
    {"hello": ...} category and never restores it. Before the guard, a later File.init_yara()
    recompiled every time so the leak was harmless; with the guard, test_get_yaras's
    File.init_yara() is a no-op, so get_yara("CAPE") looks up the polluted dict, finds no CAPE
    rules, and returns [] -> AssertionError.

Two fixes:
  - objects.py get_yara(): if the requested category isn't present, force ONE full recompile
    before giving up. A live category is never silently skipped just because yara_rules was
    replaced/limited elsewhere or a prior init was partial. Production-robust; preserves the
    guard's perf win for the normal (category-present) path.
  - test_objects.py test_get_yara(): save/restore File.yara_rules so the single-category
    injection no longer leaks into later tests.
perf: ClamAV parallel prefetch, shared pebble pool, PE checksum skip, YARA init guard
@pull pull Bot locked and limited conversation to collaborators Jul 8, 2026
@pull pull Bot added the ⤵️ pull label Jul 8, 2026
@pull
pull Bot merged commit 4bca33b into threatcode:master Jul 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants