aws / amazon-s3-encryption-client-dotnet

An encryption client that allows you to secure your sensitive data before you send it to Amazon S3.
https://aws.github.io/amazon-s3-encryption-client-dotnet/
Apache License 2.0
15 stars 10 forks source link

Multipart upload raise HashStream exception when using FilePath #3

Closed davorinv closed 3 years ago

davorinv commented 3 years ago

Describe the bug

I'm testing client-side AES-GCM encryption on file > 100MB. The transfer starts but then the upload raise an exception on 2nd chunk.

To Reproduce

Start multipart upload using TransferUtilityUploadRequest.FilePath or UploadPartRequest.FilePath

Versions

<TargetFramework>netcoreapp3.1</TargetFramework>
<PackageReference Include="Amazon.Extensions.S3.Encryption" Version="1.0.0" />
<PackageReference Include="AWSSDK.S3" Version="3.5.0.7" />

Expected behavior

The upload should succeed

Actual behavior

HashStream does not support base streams that are not capable of reading or writing

Workaround

Use TransferUtilityUploadRequest.InputStream or UploadPartRequest.InputStream

Stack trace

at Amazon.Runtime.Internal.Util.HashStream.ValidateBaseStream()
at Amazon.Runtime.Internal.Util.HashStream..ctor(Stream baseStream, Byte[] expectedHash, Int64 expectedLength)
at Amazon.Runtime.Internal.Util.HashStream`1..ctor(Stream baseStream, Byte[] expectedHash, Int64 expectedLength)
at Amazon.Runtime.Internal.Util.MD5Stream..ctor(Stream baseStream, Byte[] expectedHash, Int64 expectedLength)
at Amazon.S3.Model.Internal.MarshallTransformations.UploadPartRequestMarshaller.Marshall(UploadPartRequest uploadPartRequest)
at Amazon.S3.Model.Internal.MarshallTransformations.UploadPartRequestMarshaller.Marshall(AmazonWebServiceRequest input)
at Amazon.Runtime.Internal.Marshaller.PreInvoke(IExecutionContext executionContext)
at Amazon.Runtime.Internal.Marshaller.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.PipelineHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Extensions.S3.Encryption.Internal.SetupEncryptionHandler.<>n__0[T](IExecutionContext executionContext)
at Amazon.Extensions.S3.Encryption.Internal.SetupEncryptionHandler.<InvokeAsync>d__10`1.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9`1.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at Amazon.S3.Internal.AmazonS3ExceptionHandler.<InvokeAsync>d__1`1.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at Amazon.Runtime.Internal.ErrorCallbackHandler.<InvokeAsync>d__5`1.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at Amazon.Runtime.Internal.MetricsHandler.<InvokeAsync>d__1`1.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at Amazon.S3.Transfer.Internal.MultipartUploadCommand.<UploadPartAsync>d__24.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at Amazon.S3.Transfer.Internal.BaseCommand.<WhenAllOrFirstExceptionAsync>d__5`1.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Amazon.S3.Transfer.Internal.MultipartUploadCommand.<ExecuteAsync>d__23.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at AesTest.Program.<UploadAes>d__5.MoveNext() in W:\dev\AesTest\AesTest\Program.cs:line 121
hunanniu commented 3 years ago

This has been addressed