oasis-open / cti-python-stix2

OASIS TC Open Repository: Python APIs for STIX 2
https://stix2.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
356 stars 113 forks source link

Fix pattern semantic equivalence comparison expression DNF transformer bug #534

Closed chisholm closed 2 years ago

chisholm commented 2 years ago

Fixes #533 .

This PR fixes the comparison expression DNF transformer to catch the exception caused by inconsistent SCO types among comparison expression AND operands, and drop the AND expression. This resolves the problem and additionally enables a nice simplification. For example, the example from the issue was:

[(a:b=1 OR b:c=1) AND (b:d=1 OR c:d=1)]

which would have transformed to:

[(a:b=1 AND b:d=1) OR (a:b=1 AND c:d=1) OR (b:c=1 AND b:d=1) OR (b:c=1 AND c:d=1)]

The transformer will now drop the first, second, and fourth AND expressions due to their mixed SCO types (which means they'd be impossible to satisfy anyway). The result is simply:

[b:c=1 AND b:d=1]

which is semantically equivalent to the original: only a b SCO could have satisfied it, which is obvious in its simplified form.

Also:

codecov-commenter commented 2 years ago

Codecov Report

Merging #534 (3086b7a) into master (81550ca) will increase coverage by 0.00%. The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #534   +/-   ##
=======================================
  Coverage   87.28%   87.29%           
=======================================
  Files         153      153           
  Lines       18025    18033    +8     
=======================================
+ Hits        15734    15742    +8     
  Misses       2291     2291           
Impacted Files Coverage Δ
stix2/test/test_pattern_equivalence.py 100.00% <ø> (ø)
stix2/equivalence/pattern/transform/comparison.py 74.62% <100.00%> (+1.61%) :arrow_up:
stix2/patterns.py 62.01% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 81550ca...3086b7a. Read the comment docs.