Skip to content

fix: DER length decoding bounds check to raise ValueError - #234

Closed
abhi-0203 wants to merge 2 commits into
ofek:masterfrom
abhi-0203:fix-der-bounds-check
Closed

abhi-0203 wants to merge 2 commits into
ofek:masterfrom
abhi-0203:fix-der-bounds-check

Conversation

@abhi-0203

Copy link
Copy Markdown

Closes #229\n\nAdds a bounds check in decode_length to ensure the claimed length does not exceed the buffer, preventing IndexError on malformed DER input. This aligns with the documented ValueError behavior and improves security for services that catch ValueError around parsing.

…d input

decode_length and decode_der trusted attacker-controlled length bytes
without validating offsets against the buffer. Malformed DER input
(e.g. a length field claiming 254 bytes from a 66-byte buffer) raised
IndexError instead of the documented ValueError.

Add bounds checking in decode_length (offset bounds, num_length_bytes
overflow, zero-length long form) and in decode_der (validate offsets
after each decode_length call before indexing into the buffer).

Closes #229
@abhi-0203 abhi-0203 closed this by deleting the head repository Aug 30, 2026
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.

decode_der raises IndexError on malformed length fields

1 participant