-
-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug in commit 'Handle BER-encoded indefinite length values better' #249
Comments
Today I discovered exactly the problem reported here. |
Can you provide an example of an encoded ASN.1 value that exposes this bug? From my understanding the header can’t end in This is why I’d like an example so I can see what is actually going on. |
I mentioned the example in bug #195 already. See my last comments there. The certificate in the attached zip file... The highest bit you mentioned - this is about the short form (length up to 127). There can be a number of length octets in header for a length over 127. The last octet can be 0x80 quite easily. |
Posting an example on a different issue isn’t as helpful as posting it on the issue about the bug. My recollection is fuzzy, but I thought the high bit was not set on any of the length bits? Or are you saying it is only not set on a single-byte-encoded length? |
Yeah, so that was most likely the source of the bug in the implementation. https://luca.ntop.org/Teaching/Appunti/asn1.html Confirms the high bit only matters on the first byte. |
For example I have the problem in this structure. |
I am afraid that test can't be easily written in only one if statement. Identification/tag can occupy more than the first octet of the header. So self._header[1] is not necessarily the first length octet... |
I've found the bug in this commit:
link to commit c29117fd57deb80fb345cf76cad9d0d48e8bbf17
Definition of length of asn1 package in this part of code "self._header[-1:] == b'\x80':" is incorrect.
According this documentation:
https://www.w3.org/Protocols/HTTP-NG/asn1.html
For the definite form, if the length is less than 128, you just use a single byte, with the high bit set to zero. Otherwise the high bit is set to one, and the low seven bits set to the length of length. The length is then encoded in that many bytes.
More correct code is:
The text was updated successfully, but these errors were encountered: