Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

FromBase64Transform.InputBlockSize set to 4 instead of 1 #39599

Merged
merged 3 commits into from
Aug 20, 2019
Merged

FromBase64Transform.InputBlockSize set to 4 instead of 1 #39599

merged 3 commits into from
Aug 20, 2019

Conversation

gfoidl
Copy link
Member

@gfoidl gfoidl commented Jul 18, 2019

Fixes https://github.com/dotnet/corefx/issues/39583 and sets FromBase64Transform.CanTransformMultipleBlocks = true (cf. https://github.com/dotnet/corefx/issues/39583#issuecomment-512854180).

@bartonjs bartonjs added breaking-change Issue or PR that represents a breaking API or functional change over a prerelease. area-System.Security labels Jul 19, 2019
public int OutputBlockSize => 3;
public bool CanTransformMultipleBlocks => false;
public bool CanTransformMultipleBlocks => true;
Copy link
Member Author

Choose a reason for hiding this comment

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

though that means it'll almost never use the stackalloc buffers
(from https://github.com/dotnet/corefx/issues/39583#issuecomment-512854180)

Are there any statistics about the typical inputCount (i.e. stream length on which CryptoStream should operate)? With these numbers the buffers could be tweaked (stackalloc / renting).

If not, I believe the current implementation of stackalloc / renting is still good.

Copy link
Member

Choose a reason for hiding this comment

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

Are there any statistics about the typical inputCount (i.e. stream length on which CryptoStream should operate)?

Nope.

The numbers I do have: apisof.net reports 1% APIPort usage for FromBase64Transform, and 0.4% for ToBase64Transform (25% CryptoStream)... and RC2 has almost more usage than that (somehow). Convert.ToBase64String(byte[]) has 51.4% usage, and Convert.FromBase64String is 43,8% usage.

So "no idea what the inputs into this are, but it's definitely not the common way of doing Base64".

@gfoidl gfoidl marked this pull request as ready for review July 19, 2019 17:03
public int OutputBlockSize => 3;
public bool CanTransformMultipleBlocks => false;
public bool CanTransformMultipleBlocks => true;
Copy link
Member

Choose a reason for hiding this comment

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

I'd like to see at least some test have to change as a result of this. Can you add a test that just checks that the block sizes and can-transform match what we want them to be? :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Tests are added with 886b05b

{
using (var transform = new ToBase64Transform())
{
Assert.False(transform.CanTransformMultipleBlocks);
Copy link
Member

Choose a reason for hiding this comment

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

Is ToBase64Transform already effectively implemented as "true" here? (TransformBlock accepting an integer multiple of the input block size, TransformFinalBlock accepting any arbitrary amount of data) Or would flipping it to true actually cause failures?

Copy link
Member Author

Choose a reason for hiding this comment

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

Is ToBase64Transform already effectively implemented as "true" here?

No it's not. It just transforms one block at a time.

// For now, only convert 3 bytes to 4
Span<byte> input = inputBuffer.AsSpan(inputOffset, InputBlockSize);
Span<byte> output = outputBuffer.AsSpan(outputOffset, OutputBlockSize);

else if (inputCount > InputBlockSize)
{
ThrowHelper.ThrowArgumentOutOfRange(ThrowHelper.ExceptionArgument.inputCount);
}
// Again, for now only a block at a time
Span<byte> input = inputBuffer.AsSpan(inputOffset, inputCount);

See also https://github.com/dotnet/corefx/issues/39583#issuecomment-513304310 for this.

Or would flipping it to true actually cause failures?

This test

public static void ValidateToBase64CryptoStream(string data, string encoding)
will fail with these
yield return new object[] { "foobar", "Zm9vYmFy" };
test-data.

@maryamariyan
Copy link

Retriggering CI to see if Windows x86_Release still fails

@bartonjs
Copy link
Member

System.Net.Http.Functional.Tests.SocketsHttpHandlerTest_Http2.Http2_PendingReceive_SendsReset(doRead: False) failed on Windows x64 Debug; but the details loader isn't opening.

Triggering again to hopefully get a clean run.

@bartonjs bartonjs merged commit b456415 into dotnet:master Aug 20, 2019
@gfoidl gfoidl deleted the crypto-base64-fix-inputblocksize branch August 21, 2019 07:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Security breaking-change Issue or PR that represents a breaking API or functional change over a prerelease.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FromBase64Transform.InputBlockSize = 1 instead of 4
4 participants