Skip to content

asn1rt: fix ASN1Set.intersect() - #220

Merged
mitshell merged 1 commit into
pycrate-org:masterfrom
TheeCoderAhmed:fix/asn1set-intersect
Nov 2, 2026
Merged

mitshell merged 1 commit into
pycrate-org:masterfrom
TheeCoderAhmed:fix/asn1set-intersect

Conversation

@TheeCoderAhmed

Copy link
Copy Markdown
Contributor

Fixes #214.

ASN1Set.intersect() in the runtime failed for integer sets in both cases from the issue, and the extensible case had one more problem past the one reported:

  • Non-extensible sets (ev=None): is_ext() tested self._er is not None, but __init__ sets _er = [] for a non-extensible set, so every set looked extensible. intersect() then iterated _ev, which is None, and raised TypeError: 'NoneType' object is not iterable. is_ext() now tests _ev, which is None exactly when the set is not extensible.
  • Extensible sets (ev=[]): ret._init() was called without its sort_root, sort_ext arguments. With that fixed, step 4.3 still failed. It copies "root values not intersecting" from self.root and S.root, and for integer sets .root also holds the ASN1RangeInt objects. Those ranges went into ret._ev, and _init() then raised ASN1Err: ASN1RangeInt(0..10): unable to compare with 0. Step 4.3 now copies the individual root values (_rv) only; the root ranges are already merged into ret._er in step 4.1.

Added test_setobj_intersect() to test/test_asn1rt.py and called it from TestPycrate.test_asn1rt in test/test_pycrate.py. It runs the reproduction from the issue for ev=None and ev=[] and checks that the root is 5..10. It also checks that an individual root value outside the intersection ends up in the extension. It fails on master with the TypeError above and passes with the change. The rest of test/test_asn1rt.py still passes.

is_ext() tested _er, which is an empty list (not None) for a non-extensible set, so intersect() treated every set as extensible and then iterated _ev, which is None. For extensible sets, intersect() called _init() without its two arguments, and step 4.3 copied root ranges (from .root) into the extension values, which _init() then could not sort against integers. Test _ev in is_ext(), pass sort_root and sort_ext to _init(), and only copy individual root values in step 4.3, since the root ranges are already merged into the extension ranges in step 4.1.

Fixes pycrate-org#214
@mitshell
mitshell merged commit eec5c4f into pycrate-org:master Nov 2, 2026
13 checks passed
@mitshell

mitshell commented Nov 2, 2026

Copy link
Copy Markdown
Member

Thanks for the fix !

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.

The runtime ASN1Set.intersect raises for integer sets

2 participants