One function

_parse in wbond/asn1crypto

The author described this change as Fix indefinite-length parsing. It counts as a record because the check below fails on the code as it stood at d9866902f and passes on 65554db7c, with nothing else changed between the two runs.

Fix saved2021-08-14
Sharing licenceMIT · LICENSE
Change size+3 4

What the code was meant to do, written into the code itself as a docstring

Parses a byte string into component parts :param encoded_data: A byte string that contains BER-encoded data :param data_len: The integer length of the encoded data :param pointer: The index in the byte string to parse from :param lengths_only: A boolean to cause the call to return a 2-element tuple of the integer number of bytes in the header and the integer number of bytes in the contents. Internal use only. :param depth: The recursion depth when evaluating indefinite-length encoding. :return: A 2-element tuple: - 0: A tuple of (class_, method, tag, header, content, trailer) - 1: An integer indicating how many bytes were consumed

The change

6565 # just scanned looking for \x00\x00, nested indefinite length values
6666 # would not work.
6767 contents_end = pointer
68- while contents_end < data_len:
69- sub_header_end, contents_end = _parse(encoded_data, data_len, contents_end, lengths_only=True, depth=depth+1)
70- if contents_end == sub_header_end and encoded_data[contents_end - 2:contents_end] == b'\x00\x00':
71- break
68+ while data_len < contents_end + 2 or encoded_data[contents_end:contents_end+2] != b'\x00\x00':
69+ _, contents_end = _parse(encoded_data, data_len, contents_end, lengths_only=True, depth=depth+1)
70+ contents_end += 2
7271 trailer = b'\x00\x00'
7372
7473 if contents_end > data_len:

The check that tells the two apart

failpass·tests/test_parser.py::ParserTests::test_parser_indef_long_zero_length

Check file tests/test_parser.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 itd9866902fc4aea3ef38df3765f5ab91f7e7b8af7
Broken version dated2021-08-14
Moduleasn1crypto.parser
Units changed_parse
Fingerprinte140918aa34f41bd
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