Skip to content

Cap DERReencode recursion depth (GH #1353) - #1354

Open
Coralesoft wants to merge 1 commit into
weidai11:masterfrom
Coralesoft:fix/issue-1353-derreencode-depth
Open

Cap DERReencode recursion depth (GH #1353)#1354
Coralesoft wants to merge 1 commit into
weidai11:masterfrom
Coralesoft:fix/issue-1353-derreencode-depth

Conversation

@Coralesoft

@Coralesoft Coralesoft commented May 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #1353.

DERReencode walks nested constructed indefinite BER without a depth limit, so a crafted chain of 0x30 0x80 sequences can exhaust the thread stack. PKCS8PrivateKey import reaches this path via BERDecodeOptionalAttributes.

The cap is 32 levels, matching OpenSSL ASN1_MAX_CONSTRUCTED_NEST. Deeper inputs throw BERDecodeError instead of recursing further.

What changed

  • Added internal DERReencodeLimited(source, dest, depth) with the cap check at entry.
  • Kept public DERReencode as a depth-0 wrapper.

DERReencode had no depth limit when walking nested constructed indefinite BER. A crafted chain of 0x30 0x80 sequences could recurse until the thread stack ran out.

Add DERReencodeLimited and keep DERReencode as a depth-0 wrapper. The limit is 32 levels, matching OpenSSL ASN1_MAX_CONSTRUCTED_NEST. Deeper inputs now throw BERDecodeError.
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++ DERReencode recurses through nested indefinite ASN.1 without a depth limit

1 participant