Skip to content

Change ValidateDer to iterative evaluation#128874

Merged
bartonjs merged 4 commits into
dotnet:mainfrom
bartonjs:iterative_validateder
Jun 3, 2026
Merged

Change ValidateDer to iterative evaluation#128874
bartonjs merged 4 commits into
dotnet:mainfrom
bartonjs:iterative_validateder

Conversation

@bartonjs

@bartonjs bartonjs commented Jun 2, 2026

Copy link
Copy Markdown
Member

Since this change doesn't eagerly dive into CONSTRUCTED values, it will change when it encounters a value that gets rejected, but since it doesn't report where the invalid value was found, that doesn't matter.

Since this change doesn't eagerly dive into CONSTRUCTED values,
it will change when it encounters a value that gets rejected, but since
it doesn't report where the invalid value was found, that doesn't matter.
@bartonjs bartonjs added this to the 11.0.0 milestone Jun 2, 2026
@bartonjs bartonjs self-assigned this Jun 2, 2026
Copilot AI review requested due to automatic review settings June 2, 2026 00:44
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @bartonjs, @vcsjones, @dotnet/area-system-security
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates DER validation in Internal.Cryptography.Helpers.ValidateDer to use an iterative traversal (explicit stack/queue) instead of recursive descent, preventing StackOverflowException on deeply nested constructed ASN.1 values. It also adds an X509 CertificateRequest regression test that exercises very deep nesting through OtherRequestAttributes.

Changes:

  • Rework Helpers.ValidateDer to iteratively validate nested constructed values (avoids recursion-based stack overflow).
  • Add a regression test covering both valid and intentionally-invalid, deeply nested OtherRequestAttributes DER payloads.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/Helpers.cs Replaces recursive DER validation with iterative processing; introduces an overflow path for deep nesting.
src/libraries/System.Security.Cryptography/tests/X509Certificates/CertificateCreation/CertificateRequestApiTests.cs Adds a theory validating behavior with very deep nesting (and an invalid mutation) in OtherRequestAttributes.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 2, 2026 00:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

@vcsjones vcsjones left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, some nits that could be addressed.

Copilot AI review requested due to automatic review settings June 2, 2026 22:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

@bartonjs bartonjs enabled auto-merge (squash) June 2, 2026 23:04
@bartonjs bartonjs merged commit 432c2e4 into dotnet:main Jun 3, 2026
95 checks passed
@bartonjs bartonjs deleted the iterative_validateder branch June 3, 2026 15:46
@dotnet-milestone-bot dotnet-milestone-bot Bot modified the milestones: 11.0.0, 11.0-preview6 Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants