One function
_dump_header in wbond/asn1crypto
The author described this change as “Fix encoding of tag values over 30”. It counts as a record because the check below fails on the code as it stood at 2199e11bc and passes on e2d7e4c8f, with nothing else changed between the two runs.
Projectwbond/asn1crypto
Fix saved2019-09-23
Sharing licenceMIT · LICENSE
Change size+5 −3
What the code was meant to do, written into the code itself as a docstring
Constructs the header bytes for an ASN.1 object :param class_: An integer ASN.1 class value: 0 (universal), 1 (application), 2 (context), 3 (private) :param method: An integer ASN.1 method value: 0 (primitive), 1 (constructed) :param tag: An integer ASN.1 tag value :param contents: A byte string of the encoded byte contents :return: A byte string of the ASN.1 DER header
The change
| 26 | 26 | id_num |= method << 5 | |
| 27 | 27 | ||
| 28 | 28 | if tag >= 31: | |
| 29 | - | header += chr_cls(id_num | 31) | |
| 29 | + | cont_bit = 0 | |
| 30 | 30 | while tag > 0: | |
| 31 | - | continuation_bit = 0x80 if tag > 0x7F else 0 | |
| 32 | - | header += chr_cls(continuation_bit | (tag & 0x7F)) | |
| 31 | + | header = chr_cls(cont_bit | (tag & 0x7f)) + header | |
| 32 | + | if not cont_bit: | |
| 33 | + | cont_bit = 0x80 | |
| 33 | 34 | tag = tag >> 7 | |
| 35 | + | header = chr_cls(id_num | 31) + header | |
| 34 | 36 | else: | |
| 35 | 37 | header += chr_cls(id_num | tag) | |
| 36 | 38 |
The check that tells the two apart
fail→pass·tests/test_core.py::CoreTests::test_large_tag_encode
Check file tests/test_core.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it2199e11bcb179f679f9880a6aa2047da880efae2
Broken version dated2019-09-23
Moduleasn1crypto.parser
Units changed_dump_header
Fingerprint400833237d839dd2
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in wbond/asn1crypto
- 2021-12-05Fix Clearance type definition
- 2021-11-21Fix tagging for RoleSyntax and SecurityCategory
- 2021-08-14_parse
- 2017-11-28Fix type checking in pem.armor()
- 2017-02-07_parse
- 2016-03-29uri_to_iri