You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
x509_parse (lib/std/crypto/x509.w) never validates claimed DER content lengths against buf_len, so a truncated certificate whose trailing element header fits returns success with offsets/lengths escaping the buffer. Downstream consumers then perform raw unbounded reads over the escaped ranges. Reachable from the TLS peer-cert path (lib/std/tls.w:589-590).
Vendored-parse probe (.audit/probes/x509/parse_escape.w) with an openssl-generated 771-byte RSA-2048 cert (full parse verified: rc=1, n=149/256, e=407/3, sig=515/256 — matches openssl anatomy):
buf_len=520 (cut inside signatureValue content; TLV header fits): returns 1 with sig_start=515, sig_len=256 — the range 515..771 escapes the 520-byte bound by 251 bytes.
buf_len=200 (mid-modulus cut): returns 0 (fail-closed). Only trailing-element truncation escapes with rc=1.
der_read_tl checks only header fit; der_skip and all cs + cl propagations are unclamped, and no stored start+len is validated. Escaped-range consumers (all raw reads): sha256_hash over the tbs range (:367), rsa_pkcs1_sha256_verify n/e/sig ranges (:372-377), oid_match (:75-83, which takes no length at all), ECDSA r/s/point reads. Adversarial cs + cl i32 wraparound collapses into the same missing-clamp class.
Notes (not applied; audit is read-only)
Clamp every cs + cl and every stored start+len to buf_len, failing closed with 0. Suggested regression: trailing-truncated cert must return 0 and never emit escaping offsets.
Verdict. Established. der_read_tl validates only that the tag and length header fit within buf_len; it never checks that content_start + content_len fits. der_skip returns cs + cl unclamped, and x509_parse stores element start/len without a final bounds check, so a certificate truncated inside a trailing element (whose TLV header still fits) parses as success with offsets that escape the buffer. x509_verify_signature then performs raw reads over those ranges (sha256_hash on the tbs range, rsa_pkcs1_sha256_verify on the n/e/sig ranges), i.e. out-of-bounds reads driven by attacker-controlled length fields. Reachable from the TLS peer-certificate path.
Tested.
Source
main @ 5809ac1 (2026-09-14); x509.w unchanged since the reported revision 450733e
Compilers
with v0.15.2.1 built from 5809ac1 (staging worktree); a compiler built from 450733e with the nightly-20260903 seed. Same result
Platform
macOS Darwin 25.6.0 arm64
Repro of the primitive (der_read_tl inlined verbatim from x509.w:28-60, fed a 4-byte buffer [0x04, 0x82, 0x01, 0x00] — tag OCTET STRING, long-form length 0x0100 = 256):
content_start = 4 (>= 0, i.e. SUCCESS; not the -1 fail sentinel)
content_len = 256
content_start + content_len = 260 -- escapes buf_len = 4 by 256 bytes
Both compilers. The header-fit guard (p + num_len_bytes > buf_len) passes because 2 + 2 == 4, and there is no content_start + content_len <= buf_len check, so a range 256 bytes past the buffer is returned as valid. This is the exact primitive behind the report's full-cert numbers (buf_len 520 → sig_start 515, sig_len 256, escaping by 251).
der_read_tl: only header bounds checked (x509.w:29,36,50); the two *(out_content_start) = p; *(out_content_len) = length stores never validate p + length <= buf_len.
x509_parse stores sig_start/sig_len, tbs_start/tbs_len, key ranges from these outputs with no start + len <= buf_len gate (x509.w:190-300).
Escaped-range consumers, all raw reads: sha256_hash(cert_buf + cert.tbs_start, cert.tbs_len, ...) and rsa_pkcs1_sha256_verify(..., cert_buf + cert.sig_start, cert.sig_len, ...) (x509.w:367,372-377), plus oid_match which takes no length at all (:75-83).
Additional hazard.content_len is assembled from up to 4 length bytes into an i32 (x509.w:56-58), so a crafted 0x84 7F FF FF FF length is negative or near INT_MAX; cs + cl can then wrap. Any fix must clamp before, not after, the addition. Same missing-clamp class as the report notes.
Root cause. A DER length-validation omission: header bounds are checked, content bounds are not. No compiler defect; established by the primitive repro plus the consumer trace. I did not drive the full x509_parse end to end because it and x509_verify_signature are private unsafe fn and need a real DER cert; the report did that with an openssl-generated 771-byte RSA-2048 cert and got rc=1 with escaping sig offsets, consistent with the primitive above.
Severity. High and security-relevant: out-of-bounds reads over attacker-supplied certificate content, reachable from TLS peer-cert verification (lib/std/tls.w:589-590 per the report). The read escapes are bounded only by where the process's mapping ends, so worst case is a crash (info-leak potential depends on what the hash/verify does with the bytes).
Validator gap. No test feeds a truncated certificate; combined with #1053/#1055 (crypto suites don't compile / not wired in), the whole x509 path has no negative-input coverage.
Related.#1052/#1051/#1054/#1055 are other crypto-path defects; this one is the DER parser. No open PR.
Recommendation — champion. Add content-bounds validation: in der_read_tl, after computing content_start/content_len, fail closed (content_start = -1) unless content_len >= 0 and content_start + content_len <= buf_len (compute the comparison in a way that cannot overflow, e.g. content_len > buf_len - content_start). Clamp/validate der_skip's return and every stored start + len in x509_parse the same way. Acceptance criteria:
The primitive repro above returns the -1 fail sentinel for a content range exceeding buf_len.
A trailing-truncated real cert makes x509_parse return 0 and emit no escaping offsets.
A cert with a crafted oversize/negative length returns 0 without integer wrap.
Blockers / not tested. Full x509_parse/TLS path not driven end to end (private, needs a DER fixture); the OOB read itself was not observed under a sanitizer here. The primitive-level repro plus the consumer trace establish the defect. Linux/Windows not exercised.
Triage 2026-10-25, with v0.15.3.0 (main a261b65): reproduced in source: der_read_tl (lib/std/crypto/x509.w:28) still checks that the tag and length header fit in buf_len (:29, :36, :50) and never that content_start + content_len does.
pre-release: a truncated peer certificate drives out-of-bounds reads through std.tls; the bound check is one comparison.
Fixed on main by 3f96513 (PR #2671, stack #2678; battery green on the stack top 0008bf2). The commit message names the root-cause line and the regression test.
Activity
ehartford commentedon Sep 16, 2026
Review: reproduced
Verdict. Established.
der_read_tlvalidates only that the tag and length header fit withinbuf_len; it never checks thatcontent_start + content_lenfits.der_skipreturnscs + clunclamped, andx509_parsestores element start/len without a final bounds check, so a certificate truncated inside a trailing element (whose TLV header still fits) parses as success with offsets that escape the buffer.x509_verify_signaturethen performs raw reads over those ranges (sha256_hashon the tbs range,rsa_pkcs1_sha256_verifyon the n/e/sig ranges), i.e. out-of-bounds reads driven by attacker-controlled length fields. Reachable from the TLS peer-certificate path.Tested.
main@ 5809ac1 (2026-09-14);x509.wunchanged since the reported revision 450733ewith v0.15.2.1built from 5809ac1 (staging worktree); a compiler built from 450733e with the nightly-20260903 seed. Same resultRepro of the primitive (
der_read_tlinlined verbatim fromx509.w:28-60, fed a 4-byte buffer[0x04, 0x82, 0x01, 0x00]— tag OCTET STRING, long-form length 0x0100 = 256):Both compilers. The header-fit guard (
p + num_len_bytes > buf_len) passes because2 + 2 == 4, and there is nocontent_start + content_len <= buf_lencheck, so a range 256 bytes past the buffer is returned as valid. This is the exact primitive behind the report's full-cert numbers (buf_len 520 → sig_start 515, sig_len 256, escaping by 251).Source pins (5809ac1).
der_read_tl: only header bounds checked (x509.w:29,36,50); the two*(out_content_start) = p; *(out_content_len) = lengthstores never validatep + length <= buf_len.der_skipreturnscs + clunclamped (x509.w:72).x509_parsestoressig_start/sig_len,tbs_start/tbs_len, key ranges from these outputs with nostart + len <= buf_lengate (x509.w:190-300).sha256_hash(cert_buf + cert.tbs_start, cert.tbs_len, ...)andrsa_pkcs1_sha256_verify(..., cert_buf + cert.sig_start, cert.sig_len, ...)(x509.w:367,372-377), plusoid_matchwhich takes no length at all (:75-83).Additional hazard.
content_lenis assembled from up to 4 length bytes into ani32(x509.w:56-58), so a crafted0x84 7F FF FF FFlength is negative or nearINT_MAX;cs + clcan then wrap. Any fix must clamp before, not after, the addition. Same missing-clamp class as the report notes.Root cause. A DER length-validation omission: header bounds are checked, content bounds are not. No compiler defect; established by the primitive repro plus the consumer trace. I did not drive the full
x509_parseend to end because it andx509_verify_signatureare privateunsafe fnand need a real DER cert; the report did that with an openssl-generated 771-byte RSA-2048 cert and got rc=1 with escaping sig offsets, consistent with the primitive above.Severity. High and security-relevant: out-of-bounds reads over attacker-supplied certificate content, reachable from TLS peer-cert verification (
lib/std/tls.w:589-590per the report). The read escapes are bounded only by where the process's mapping ends, so worst case is a crash (info-leak potential depends on what the hash/verify does with the bytes).Validator gap. No test feeds a truncated certificate; combined with #1053/#1055 (crypto suites don't compile / not wired in), the whole x509 path has no negative-input coverage.
Related. #1052/#1051/#1054/#1055 are other crypto-path defects; this one is the DER parser. No open PR.
Recommendation — champion. Add content-bounds validation: in
der_read_tl, after computingcontent_start/content_len, fail closed (content_start = -1) unlesscontent_len >= 0andcontent_start + content_len <= buf_len(compute the comparison in a way that cannot overflow, e.g.content_len > buf_len - content_start). Clamp/validateder_skip's return and every storedstart + leninx509_parsethe same way. Acceptance criteria:-1fail sentinel for a content range exceedingbuf_len.x509_parsereturn 0 and emit no escaping offsets.test/and runs (needs the [tests] crypto suites (bigint/rsa/crypto) not executable: stale unsafe:/-> void syntax #1053/[crypto] ec/ecdsa suites stale (unexecutable) and P-256 public API header contradicts private visibility #1055 suite repair).Blockers / not tested. Full
x509_parse/TLS path not driven end to end (private, needs a DER fixture); the OOB read itself was not observed under a sanitizer here. The primitive-level repro plus the consumer trace establish the defect. Linux/Windows not exercised.ehartford commentedon Oct 25, 2026
Triage 2026-10-25,
with v0.15.3.0(main a261b65): reproduced in source:der_read_tl(lib/std/crypto/x509.w:28) still checks that the tag and length header fit inbuf_len(:29,:36,:50) and never thatcontent_start + content_lendoes.pre-release: a truncated peer certificate drives out-of-bounds reads through
std.tls; the bound check is one comparison.std.crypto.x509: a DER element's content must fit the buffer, so a tr…
ehartford commentedon Oct 25, 2026
Fixed on main by 3f96513 (PR #2671, stack #2678; battery green on the stack top 0008bf2). The commit message names the root-cause line and the regression test.