Repository navigation
Conversation
mmguero
added a commit
to mmguero-dev/Malcolm
that referenced
this pull request
Oct 15, 2026
filebeat-process-zeek-folder.sh ran the find over the extraction directory regardless of safe-extract.py's exit status, so any logs written before a failure got symlinked into current/ and ingested. Check the exit status, log the failure to stderr, and exit the per-file subshell so the rest of the batch continues. Pairs with cisagov#1239, which removes partial output on failed extraction. Signed-off-by: Seth Grover <seth.d.grover@gmail.com>
Merged
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.
Description
safe_extract removes its destination only for ArchiveBombError. Truncated compression streams, a bad ZIP checksum, or a missing source can leave an empty or partially populated directory even though extraction fails. The Filebeat caller proceeds to discover extracted .log files after the command, so partial output can be mistaken for completed input.
Clean up the newly created destination for ordinary extraction exceptions as well, and include MIME detection in the guarded operation. Directory creation remains outside the try block: a pre-existing destination is never removed. The original exception is re-raised and source archives are preserved. Successful extraction and configured archive-bomb limits keep their existing behavior.
Add libarchive-c==5.3 to shared test dependencies, matching the existing Filebeat runtime requirement. There is no new production dependency.
Related issue(s)
New reproducible regression found on current contributor-prs. No existing tracking issue or overlapping open PR was found. The existing relative-path and zstd extraction fixes on that branch are retained.
Type of change
How has this been tested?
python -m pytest -q shared/tests/test_safe_extract_failure_cleanup.py10 cases pass on macOS and Python 3.12 using the actual command-line extractor, libarchive-c 5.3 and libmagic. Five cases fail on unchanged contributor-prs. Tests create real gzip, bzip2, xz, tar and ZIP fixtures in temporary directories and cover truncated streams, invalid ZIP CRC, a missing source, existing-destination preservation, size-limit cleanup, successful extraction, and unchanged source bytes.
A libmagic library was staged locally from an official Homebrew bottle for testing; it is not included in the PR. Black (120-column, skip string normalization), Ruff correctness checks, Python compilation and git diff --check pass. No full Filebeat container or live ingestion deployment was run.
Documentation
Was AI used in writing the code, tests, or description for this pull request?
OpenAI ChatGPT generated the patch, tests and this description. Validation included inspecting the small production diff, checking the current contributor branch and existing contributions, reproducing failures before the change, and running real archive extraction tests afterward. Maintainer review is still required.