Skip to content

fix: deterministic extraction; don't merge comparison conditions#1

Merged
hazcod merged 1 commit into
mainfrom
fix/deterministic-comparison-conditions
Jul 9, 2026
Merged

fix: deterministic extraction; don't merge comparison conditions#1
hazcod merged 1 commit into
mainfrom
fix/deterministic-comparison-conditions

Conversation

@hazcod

@hazcod hazcod commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Two related correctness bugs surfaced while running a 100,000-rule Sigma→EQL round-trip corpus. Both could silently drop a condition and made extraction non-deterministic.

Fixes

  1. matchDetectionItems map-order non-determinism — quantifier evaluation (N of selection_*, all of them) iterated the detection-item map without ordering, so collected selection order (and downstream condition order) varied per run. Now sorted.
  2. groupORConditions merges ordering comparisons — it folded field > a OR field > b into one Alternatives condition. f > a OR f > b is not a membership test, so a bound was silently dropped; the position-dependent merge made the drop non-deterministic. Ordering operators (>, >=, <, <=) are now excluded (equality/pattern operators still fold as before).

Tests

determinism_test.go asserts both same-field bounds survive across 50 runs and comparisons never gain alternatives. Full existing suite passes.

Found via the eql-parser Sigma↔EQL translator corpus (the same over-broad-merge bug existed there and was fixed in parallel). Consumers pin a released version, so nothing auto-updates.

Two related fixes surfaced by a 100k-rule round-trip corpus:

- matchDetectionItems iterated the detection-item map without ordering, so
  quantifier evaluation ("N of selection_*", "all of them") was
  non-deterministic. Sort the matched names.
- groupORConditions folded ordering comparisons (>, >=, <, <=) on the same
  field across an OR into a single Alternatives condition. `f > a OR f > b` is
  not a membership test, so this silently dropped a bound — and, because the
  merge was position-dependent, made extraction non-deterministic. Exclude
  comparison operators from the merge.

Adds regression tests asserting both same-field bounds survive across 50 runs.
@hazcod
hazcod merged commit 4a9a3b5 into main Jul 9, 2026
0 of 2 checks passed
@hazcod
hazcod deleted the fix/deterministic-comparison-conditions branch July 9, 2026 19:46
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