Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix erroneous success in AsnDecoder.ReadEncodedValue #109586

Merged
merged 1 commit into from
Nov 6, 2024

Conversation

bartonjs
Copy link
Member

@bartonjs bartonjs commented Nov 6, 2024

When AsnDecoder.ReadEncodedValue is used on a payload where the encoded length plus the number of bytes representing the encoded length plus the number of bytes representing the tag exceeds int.MaxValue it erroneously reports success.

Every known caller of this method immediately follows it with a call to a Span or Memory .Slice, which results in an ArgumentException that the requested length exceeds the number of bytes available in the buffer.

Because AsnDecoder was extracted out of AsnReader, most AsnDecoder tests are done indirectly as AsnReader tests, or are done in the same test class that tests the related functionality on AsnReader. Since there's not a clear analogue for ReadEncodedValue (that does not immediately Slice), this change introduces a new subtree for AsnDecoder tests, only populating it with (Try)ReadEncodedValue tests. It also adds "large length" tests for ReadSetOf and ReadSequence, for good measure.

Fixes #93676

When AsnDecoder.ReadEncodedValue is used on a payload where
the encoded length plus the number of bytes representing the encoded
length plus the number of bytes representing the tag exceeds int.MaxValue
it erroneously reports success.

Every known caller of this method immediately follows it with a call to
a Span or Memory .Slice, which results in an ArgumentException that the
requested length exceeds the number of bytes available in the buffer.

Because AsnDecoder was extracted out of AsnReader, most AsnDecoder tests
are done indirectly as AsnReader tests, or are done in the same test class that
tests the related functionality on AsnReader.  Since there's not a clear
analogue for ReadEncodedValue (that does not immediately Slice), this change
introduces a new subtree for AsnDecoder tests, only populating it with
(Try)ReadEncodedValue tests.  It also adds "large length" tests for ReadSetOf
and ReadSequence, for good measure.
@bartonjs bartonjs added this to the 10.0.0 milestone Nov 6, 2024
@bartonjs bartonjs self-assigned this Nov 6, 2024
@bartonjs bartonjs merged commit 8975db4 into dotnet:main Nov 6, 2024
83 checks passed
@bartonjs
Copy link
Member Author

bartonjs commented Nov 6, 2024

/backport to release/9.0-staging

Copy link
Contributor

github-actions bot commented Nov 6, 2024

Started backporting to release/9.0-staging: https://github.com/dotnet/runtime/actions/runs/11713349572

@bartonjs
Copy link
Member Author

bartonjs commented Nov 6, 2024

/backport to release/8.0-staging

@bartonjs
Copy link
Member Author

bartonjs commented Nov 6, 2024

/backport to release/6.0-staging

Copy link
Contributor

github-actions bot commented Nov 6, 2024

Started backporting to release/8.0-staging: https://github.com/dotnet/runtime/actions/runs/11713492049

Copy link
Contributor

github-actions bot commented Nov 6, 2024

Started backporting to release/6.0-staging: https://github.com/dotnet/runtime/actions/runs/11713492899

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unexpected exception type from X509Certificate2 .ctor
2 participants