Skip to content

pem: error for sections that are too large#106

Merged
djc merged 2 commits intomainfrom
limit-section-size
Apr 24, 2026
Merged

pem: error for sections that are too large#106
djc merged 2 commits intomainfrom
limit-section-size

Conversation

@djc
Copy link
Copy Markdown
Member

@djc djc commented Apr 10, 2026

Fixes #105.

First thought 64 kB might be enough (see also rustls' CERTIFICATE_MAX_SIZE_LIMIT), but I think CRLs might be a good chunk larger for large CAs, so maybe start with 10 MB?

/// A single recognised section in a PEM file.
#[non_exhaustive]
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum SectionKind {
    /// A DER-encoded x509 certificate.
    ///
    /// Appears as "CERTIFICATE" in PEM files.
    Certificate,

    /// A DER-encoded Subject Public Key Info; as specified in RFC 7468.
    ///
    /// Appears as "PUBLIC KEY" in PEM files.
    PublicKey,

    /// A DER-encoded plaintext RSA private key; as specified in PKCS #1/RFC 3447
    ///
    /// Appears as "RSA PRIVATE KEY" in PEM files.
    RsaPrivateKey,

    /// A DER-encoded plaintext private key; as specified in PKCS #8/RFC 5958
    ///
    /// Appears as "PRIVATE KEY" in PEM files.
    PrivateKey,

    /// A Sec1-encoded plaintext private key; as specified in RFC 5915
    ///
    /// Appears as "EC PRIVATE KEY" in PEM files.
    EcPrivateKey,

    /// A Certificate Revocation List; as specified in RFC 5280
    ///
    /// Appears as "X509 CRL" in PEM files.
    Crl,

    /// A Certificate Signing Request; as specified in RFC 2986
    ///
    /// Appears as "CERTIFICATE REQUEST" in PEM files.
    Csr,

    /// An EchConfigList structure, as specified in
    /// <https://www.ietf.org/archive/id/draft-farrell-tls-pemesni-05.html>.
    ///
    /// Appears as "ECHCONFIG" in PEM files.
    EchConfigList,
}

@djc djc requested review from cpu and ctz April 10, 2026 23:04
@djc djc force-pushed the limit-section-size branch from cc2841f to c1dbfc9 Compare April 10, 2026 23:07
@djc djc changed the title Limit section size pem: error for sections that are too large Apr 10, 2026
@ctz
Copy link
Copy Markdown
Member

ctz commented Apr 24, 2026

Sorry for delay on this one. Here's a list of CRLs for public issuers (top 20, DER-encoded):

12759372	out/371a00dc/DigiCertG5TLSRSA4096SHA3842021CA1-1.crl
10935863	out/9a6ec012/accvca120_der.crl
9141514	out/cb3ccbb7/DigiCertGlobalG2TLSRSASHA2562020CA1-1.crl
2364354	out/49e7a442/d-trust_ssl_class_3_ca_1_2009.der.crl
2364354	out/49e7a442/d-trust_ssl_class_3_ca_1_2009.crl
731650	out/f1c1b50a/SSL.com-TLS-I-RSA-R1.crl
731650	out/97552015/SSL.com-TLS-I-RSA-R1.crl
731650	out/4200f504/SSL.com-TLS-I-RSA-R1.crl
664167	out/c32ffd9f/SSL.com-TLS-I-ECC-R2.crl
664167	out/945bbc82/SSL.com-TLS-I-ECC-R2.crl
664167	out/55903859/SSL.com-TLS-I-ECC-R2.crl
345026	out/85666a56/SSLcom-SubCA-SSL-RSA-4096-R1.crl
310304	out/d947432a/85QyHZnkuAw.crl
245048	out/e3b6a2db/servicesca.crl
245048	out/d48d3d23/servicesca.crl
205058	out/96bcec06/19.crl
94249	out/7bb647a6/SectigoPublicServerAuthenticationCAEVR36.crl
93350	out/eec5496b/d-trust_ssl_class_3_ca_1_ev_2009.der.crl
93350	out/eec5496b/d-trust_ssl_class_3_ca_1_ev_2009.crl

So a 10MB limit would be inappropriate. I suggest 64MB as a start?

@djc djc force-pushed the limit-section-size branch 2 times, most recently from 31acc0b to acf64ec Compare April 24, 2026 09:30
@djc
Copy link
Copy Markdown
Member Author

djc commented Apr 24, 2026

Bumped the limit to 64 MB.

Comment thread src/pem.rs Outdated
@djc djc force-pushed the limit-section-size branch from acf64ec to a54e32a Compare April 24, 2026 11:29
@djc djc enabled auto-merge April 24, 2026 11:29
@djc djc added this pull request to the merge queue Apr 24, 2026
Merged via the queue into main with commit 20bcfe1 Apr 24, 2026
20 checks passed
@djc djc deleted the limit-section-size branch April 24, 2026 11:40
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.

Memory Leak: from_buf should fail fast with an error when the input is not valid PEM data

2 participants