Conversation
write_separate_files() wrote every result with write_bytes() and counted every call. Results that render to the same file name overwrote each other silently while 'Wrote N file(s)' counted them all: the queries of a multi-condition rule under the default '{stem}.txt' template, and equal file names in different sub-directories. Results were also grouped by 'rule.id or rule.title', which merged distinct rules without id that share a title.
Results are now grouped per rule object. Results of the same source file that share an output file are joined into it, as in single-file output. Results of different source files (or binary results) that collide are reported, not overwritten, and make the command exit with status 1. 'Wrote N file(s)' counts distinct files.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This branch has not been deployed
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.
BLUF
--output-dir, results that map to the same output file overwrite each other silently. "Wrote N file(s)" still counts every write. Results are also grouped byrule.id or rule.title, so two id-less rules that share a title get merged.sigma convert -t <backend> -od out/ rules/loses queries without any error:{stem}.txtkeeps only its last query and reports "Wrote 3 file(s)" for 1 filelinux/proc.ymlandwindows/proc.ymlboth end up as oneproc.txtmainand pass with the fix. The existing--output-dirtests pass unchanged.Priority: medium
Details
Root cause:
sigma/cli/convert.py173-187: results are grouped byrule.id or rule.title. Two different rules withoutidthat share a title land in one group. They are written as one "multi-query rule" under the first rule's file name.213-249: each result is written withoutput_path.write_bytes()without checking whether this run already wrote that path.files_writtenis increased on every call.231-236: a rule with several queries renders{index}. The default template{stem}.txthas no{index}, so all queries render to the same name and only the last one survives.The new write step works in two passes:
{index}): they are joined into one file. Strings are joined with a blank line and dicts as JSON lines, as in the single-output mode. This keeps the existing behaviour oftests/files/multiple_rules/and of the correlation test, and nothing is lost.{path}/{index}.Paths are compared with
os.path.normcase(os.path.abspath(...)), so collisions that differ only in case are also caught on Windows.Before (
linux/proc.ymlandwindows/proc.yml):After:
This PR is independent of the other
--output-dirPR, which makes conversion errors fail the command. Both touchwrite_separate_files(). Whichever lands second, I'll rebase it.Testing
tests/test_convert.py, all failing onmain:test_convert_output_dir_multiple_queries_without_indextest_convert_output_dir_same_stem_different_sources(also checks that{path}/{stem}.txtwrites both)test_convert_output_dir_rules_without_id_same_titlepoetry.lock: pySigma 1.4.0, click 8.4.2, pyparsing 3.3.2):pytest --cov=sigma→ 121 passed, 1 skipped.🤖 Generated with Claude Code