Fix nondeterministic test failure for X509CertificateLoader#124617
Merged
vcsjones merged 3 commits intodotnet:mainfrom Feb 19, 2026
Merged
Fix nondeterministic test failure for X509CertificateLoader#124617vcsjones merged 3 commits intodotnet:mainfrom
vcsjones merged 3 commits intodotnet:mainfrom
Conversation
OpenSSL does not "block" trailing data after an X.509 certificate that the test thought it did. OpenSSL permits trailing data... as long as it is valid ASN.1. Certain PIDs resemble ASN.1 enough that it allows the parsing to succeed and not throw an exception like the test expected. For example, if the PID was 32816, this would be 30 80 00 00 - an indefinite length ASN.1 BER SEQUENCE. The trailing data is ignored when the parsing succeeds, its just a matter of if the trailing data causes an error (invalid ASN.1) or is ignored (valid ASN.1, but remains unconsumed).
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a nondeterministic test failure in X509CertificateLoader tests. The test LoadWrappingCertificate_PEM_WithTrailingData was failing intermittently because it used the process ID as trailing data after a certificate. OpenSSL permits trailing data as long as it is valid ASN.1, and certain PIDs could accidentally resemble valid ASN.1 structures (e.g., PID 32816 = 30 80 00 00 = indefinite length ASN.1 BER SEQUENCE), causing the test to behave differently on each run depending on the PID value.
Changes:
- Replaced nondeterministic PID-based trailing data with deterministic byte sequence
[1, 2, 3, 4] - Removed trailing whitespace on line 157
...ies/Common/tests/System/Security/Cryptography/X509Certificates/X509CertificateLoaderTests.cs
Outdated
Show resolved
Hide resolved
Contributor
|
Tagging subscribers to this area: @bartonjs, @vcsjones, @dotnet/area-system-security |
...ies/Common/tests/System/Security/Cryptography/X509Certificates/X509CertificateLoaderTests.cs
Show resolved
Hide resolved
...ies/Common/tests/System/Security/Cryptography/X509Certificates/X509CertificateLoaderTests.cs
Show resolved
Hide resolved
bartonjs
approved these changes
Feb 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
OpenSSL does not block trailing data after an X.509 certificate like the test thought it did. OpenSSL permits trailing data as long as it is valid ASN.1. The unit test in question used the process ID as the trailing data. Certain PIDs resemble ASN.1 enough that it allows the parsing to succeed and not throw an exception like the test expected. For example, if the PID was 32816, this would be 30 80 00 00 - an indefinite length ASN.1 BER SEQUENCE.
The trailing data is ignored when the parsing succeeds, it's just a matter of if the trailing data causes an error (invalid ASN.1) or is ignored (valid ASN.1, but remains unconsumed).
Fixes #123630