diff --git a/AUTHORS.rst b/AUTHORS.rst index 6523cab..f143bf6 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -7,4 +7,5 @@ The following people have contributed to Python-ASN1. Collectively they own the * Geert Jansen * Sebastien Andrivet * Filippo Santovito +* bardrop diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 0bf0185..e340d3b 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,12 @@ Changelog ========= +Unreleased +---------- + +* Reject an OID value whose last sub-identifier is truncated (last byte has bit 8 set) + instead of silently dropping it + 3.3.0 (2026-05-15) ------------------ diff --git a/src/asn1/core.py b/src/asn1/core.py index 977a914..f482ab1 100644 --- a/src/asn1/core.py +++ b/src/asn1/core.py @@ -1212,6 +1212,10 @@ def _decode_object_identifier(self, length): # type: (int) -> str sub_identifiers.append(value) value = 0 + # 8.19.2: the last byte of each sub-identifier has bit 8 set to zero + if content[-1] & 0x80: + raise Error('ASN1 decoding error: the last sub-identifier of an OID value is truncated.') + if len(sub_identifiers) == 0: raise Error('ASN1 decoding error: no sub-identifiers found.') diff --git a/tests/test_asn1.py b/tests/test_asn1.py index 0909a1a..a74e0d7 100644 --- a/tests/test_asn1.py +++ b/tests/test_asn1.py @@ -1098,6 +1098,12 @@ def test_error_non_normalised_object_identifier(self): dec.start(buf) pytest.raises(asn1.Error, dec.read) + def test_error_truncated_object_identifier(self): + for buf in (b'\x06\x02\x2a\x86', b'\x06\x05\x2a\x86\x48\x86\xf7', b'\x06\x01\x81'): + dec = asn1.Decoder() + dec.start(buf) + pytest.raises(asn1.Error, dec.read) + def test_error_bitstring_with_too_many_unused_bits(self): buf = b'\x03\x04\x08\x12\x34\x50' dec = asn1.Decoder()