Skip to content

[high] fix: [sigmf_expand] process the archive inside the SigMF-archive branch - #826

Open
elhoim wants to merge 1 commit into
MISP:mainfrom
elhoim:fix/015-sigmf-archive-indentation
Open

elhoim wants to merge 1 commit into
MISP:mainfrom
elhoim:fix/015-sigmf-archive-indentation

Conversation

@elhoim

@elhoim elhoim commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

BLUF — SigMF archive enrichment fails or succeeds depending on the order of attributes in the object.

  • Problem — in process_sigmf_archive in misp_modules/modules/expansion/sigmf_expand.py, the archive-processing block is indented one level too shallow, so it runs for every attribute rather than only the SigMF-archive one, raising UnboundLocalError on sigmf_tarfile whenever another attribute comes first.
  • Fix — re-indents that block into the SigMF-archive branch; the change is whitespace-only, with no logic change.
  • Effect — analysts enriching a sigmf-archive object get the expected sigmf-recording object instead of a generic "An error occured when processing the SigMF archive" message that depended on attribute ordering.

The archive-processing logic in process_sigmf_archive was indented at the wrong level:

        for attribute in object["Attribute"]:
            if attribute["object_relation"] == "SigMF-archive":

                sigmf_tarfile = tarfile.open(sigmf_archive_file.name, mode="r", format=tarfile.PAX_FORMAT)

            files = sigmf_tarfile.getmembers()   # <-- at `for` level, not `if` level

            for file in files:
                ...
            if sigmf_meta_attr is None:
                return {"error": "No SigMF metadata file found"}
            ...
            return {"results": {"Object": event["Object"]}}

Because the block from files = sigmf_tarfile.getmembers() through the final return was indented one level too shallow, it ran for every attribute in the object's Attribute list, not only for the SigMF-archive one. Whenever an attribute other than SigMF-archive was iterated first, sigmf_tarfile was not yet defined and the code raised UnboundLocalError, which the surrounding broad except Exception swallowed into the generic "An error occured when processing the SigMF archive" message.

Impact: any MISP analyst enriching a sigmf-archive object whose Attribute list has a non-archive attribute before the SigMF-archive attribute gets a useless generic error instead of the expected sigmf-recording object — the module effectively fails on ordering it shouldn't care about.

Fix: re-indent the archive-processing block (getting the tar members, building the meta/data attributes, constructing and returning the sigmf-recording object) so it lives inside the if attribute["object_relation"] == "SigMF-archive": branch, alongside the code that opens the tarfile. This is a whitespace-only change; no logic was altered.

Verification

  • flake8 --extend-exclude=misp_modules/lib/,tests/,website/ misp_modules/modules/expansion/sigmf_expand.py — clean, no output.
  • Full test suite: 161 passed, 4 skipped, 5 subtests passed in 121.78s (0:02:01).

Found during a review of the repository; other findings are being submitted as separate PRs.

🤖 Generated with Claude Code

The body of process_sigmf_archive that reads the tar members and builds the
sigmf-recording object was indented one level too far out, so it ran for every
attribute of the object rather than only for the SigMF-archive one. Whenever the
submitted object's first attribute is anything other than SigMF-archive,
sigmf_tarfile is still unbound when files = sigmf_tarfile.getmembers() executes,
raising UnboundLocalError; the broad except then reports it to the analyst as the
generic "An error occured when processing the SigMF archive", hiding a perfectly
valid archive that sits later in the attribute list.

The finding suggested moving only the assignment, but the loop and the object
construction that follow it depend on the same branch, so the whole block belongs
inside the if. The change is whitespace only and restores the intended fall
through to "No SigMF-archive attribute found".

Verified with flake8 on the module and the full test suite against a local
modules server: 161 passed, 4 skipped, 5 subtests passed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018dfYpyaSZd1nxSRLr8suj8
@elhoim elhoim changed the title fix: [sigmf_expand] process the archive inside the SigMF-archive branch [high] fix: [sigmf_expand] process the archive inside the SigMF-archive branch Sep 3, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant