Skip to content

Reject OID values with a truncated last sub-identifier - #300

Open
bardrop wants to merge 1 commit into
andrivet:masterfrom
bardrop-oss:fix-oid-truncated-subidentifier
Open

bardrop wants to merge 1 commit into
andrivet:masterfrom
bardrop-oss:fix-oid-truncated-subidentifier

Conversation

@bardrop

@bardrop bardrop commented Nov 22, 2026

Copy link
Copy Markdown

The OID decoder drops any bytes left after the last complete sub-identifier:

dec = asn1.Decoder(); dec.start(b'\x06\x02\x2a\x86'); dec.read()
# (Tag(...), '1.2')      -> the 0x86 is silently dropped
dec = asn1.Decoder(); dec.start(b'\x06\x05\x2a\x86\x48\x86\xf7'); dec.read()
# (Tag(...), '1.2.840')  -> the 0x86 0xf7 tail is dropped

X.690 8.19.2 says the last byte of each sub-identifier has bit 8 set to zero. So a value that ends with bit 8 set is truncated. The decoder already rejects a 0x80 leading byte and an empty value. This adds the same kind of check for a truncated last sub-identifier, so it raises asn1.Error and does not return a shorter OID.

Found by decoding random valid and invalid OIDs and comparing with pyasn1. pyasn1 rejects these inputs.

  • test_error_truncated_object_identifier fails on master and passes with the change. All 200 tests pass, and flake8 is clean.
  • I added a CHANGELOG entry and an AUTHORS line, as CONTRIBUTING asks.

The decoder dropped bytes left over after the last complete
sub-identifier, so 06 02 2a 86 was read as 1.2 and
06 05 2a 86 48 86 f7 as 1.2.840. X.690 8.19.2 says the last byte of
each sub-identifier has bit 8 set to zero, so raise an error instead.
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