Skip to content

std.crypto.x509: a DER element's content must fit the buffer, so a truncated certificate fails to parse (#1056) - #2671

Merged
ehartford merged 1 commit into
fix-1057from
fix-1056
Oct 25, 2026
Merged

ehartford merged 1 commit into
fix-1057from
fix-1056

Conversation

@ehartford

@ehartford ehartford commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Root cause: der_read_tl (lib/std/crypto/x509.w) checked that a tag and its
length bytes fit buf_len, never that the content they claim does. A
certificate cut inside its trailing signature parsed with rc=1 and a
signature range 251 bytes past its 520-byte buffer, and every reader of the
parsed offsets (the TBS hash, the RSA and ECDSA reads, oid_match) read past
it.

Content longer than the rest of the buffer (or a long-form length that
overflows) is an error, content_start = -1, in both length forms; every
der_read_tl and der_skip caller already fails closed on it.

No regression test: x509_parse is private to std and its only caller,
std.tls, reads the parsed key point within its 16640-byte record buffer, so
no observable program behavior separates the cases; the audit's
openssl-generated certificate cut at 520 bytes is what the bound answers.

Closes #1056

…uncated certificate fails to parse (#1056)

Root cause: der_read_tl (lib/std/crypto/x509.w) checked that a tag and its
length bytes fit buf_len, never that the content they claim does. A
certificate cut inside its trailing signature parsed with rc=1 and a
signature range 251 bytes past its 520-byte buffer, and every reader of the
parsed offsets (the TBS hash, the RSA and ECDSA reads, oid_match) read past
it.

Content longer than the rest of the buffer (or a long-form length that
overflows) is an error, content_start = -1, in both length forms; every
der_read_tl and der_skip caller already fails closed on it.

No regression test: x509_parse is private to std and its only caller,
std.tls, reads the parsed key point within its 16640-byte record buffer, so
no observable program behavior separates the cases; the audit's
openssl-generated certificate cut at 520 bytes is what the bound answers.
@ehartford
ehartford added this pull request to stack #2678 October 25, 2026 22:52
@ehartford ehartford changed the title fix 1056 std.crypto.x509: a DER element's content must fit the buffer, so a truncated certificate fails to parse (#1056) Oct 25, 2026
@ehartford
ehartford marked this pull request as ready for review October 25, 2026 23:05
@ehartford
ehartford merged commit 5ce1048 into main Oct 25, 2026
@ehartford
ehartford deleted the fix-1056 branch October 25, 2026 23:05
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.

[crypto] x509_parse missing content-bounds validation: truncated cert yields escaping offsets, OOB reads downstream

1 participant