-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Provide a temporary RSA decryption buffer when dest is too small #36601
Conversation
|
||
if (ret) | ||
{ | ||
Span<byte> tmpSlice = tmp.Slice(0, bytesWritten); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just tmp = tmp.Slice(0, bytesWritten);
?
|
||
if (rent != null) | ||
{ | ||
// Already cleared |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this means that if TryDecrypt fails, it won't have written anything to the buffer?
// To prevent the OOB write, decrypt into a temporary buffer. | ||
if (destination.Length < keySizeBytes) | ||
{ | ||
Span<byte> tmp = stackalloc byte[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is the stackalloc needed here? (or could you remove the initialization?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
without this the tmp
variable is not allowed to receive the stackalloc from within the if (it's a compile error to remove this).
…net/corefx#36601) * Provide a temporary RSA decryption buffer when dest is too small * Remove the semi-redundant second span variable * Add tests to ensure that destination is not tainted when decryption fails * Make Decrypt_WrongKey_OAEP_SHA256 conditional Commit migrated from dotnet/corefx@df5bba1
Fixes #33561.