-
Notifications
You must be signed in to change notification settings - Fork 14
Description
Describe the bug
Description
When downloading a file that is exactly 1GB (1000MB) using the Amazon.Extensions.S3.Encryption library, the decryption process fails with a "mac check in GCM failed" error. This issue appears to be size-specific, as files of other sizes download correctly.
Environment
.NET version:
net6.0-macos
Operating System: macOS (based on file paths), reproducible on Windows as well
Error Details
Copy[17:22:17 ERR] Failed to process restore item. RetryHelper.Value is empty. Failed file bcd074670c64//Users/ajdali/Documents/TestIssue/1000mb.txt
Amazon.Extensions.S3.Encryption.AmazonCryptoException: Failed to decrypt: mac check in GCM failed
---> Org.BouncyCastle.Crypto.InvalidCipherTextException: mac check in GCM failed
at Org.BouncyCastle.Crypto.Modes.GcmBlockCipher.DoFinal(Byte[] output, Int32 outOff) in //crypto/src/crypto/modes/GCMBlockCipher.cs:line 488
at Org.BouncyCastle.Crypto.BufferedAeadBlockCipher.DoFinal(Byte[] output, Int32 outOff) in //crypto/src/crypto/BufferedAeadBlockCipher.cs:line 235
at Org.BouncyCastle.Crypto.BufferedAeadBlockCipher.DoFinal(Byte[] input, Int32 inOff, Int32 inLen) in //crypto/src/crypto/BufferedAeadBlockCipher.cs:line 205
at Org.BouncyCastle.Crypto.IO.CipherStream.ReadAndProcessBlock() in //crypto/src/crypto/io/CipherStream.cs:line 124
at Org.BouncyCastle.Crypto.IO.CipherStream.FillInBuf() in //crypto/src/crypto/io/CipherStream.cs:line 92
at Org.BouncyCastle.Crypto.IO.CipherStream.Read(Byte[] buffer, Int32 offset, Int32 count) in //crypto/src/crypto/io/CipherStream.cs:line 72
at Amazon.Extensions.S3.Encryption.Util.AesGcmDecryptStream.Read(Byte[] buffer, Int32 offset, Int32 count)
The issue only occurs with files that are exactly 1GB (1000MB), but could occur with other files that are a multiple of this.
Files of other sizes (both smaller and larger) download and decrypt correctly
the error occurs in the BouncyCastle/AWS encryption code
This appears to be a boundary condition issue specific to the AES-GCM implementation when handling exactly 1GB of data
While I test the downloading, I found the file are not able to be downloaded are related to multi-part upload.
Impact: Files with any sizes of X times of break point (100_000_000 bytes now) (X > 1)
Those files are uploaded without encryption tag added, it might be library issue or our issue.
Workarounds Attempted
Retrying the download does not resolve the issue
The error is consistently reproducible with 1GB files
Any assistance in resolving this issue would be greatly appreciated, as it's blocking our ability to reliably handle files of this specific size.
Expected Behavior
The 1GB file should download and decrypt successfully, just like files of other sizes.
Current Behavior
the decryption process fails with a "mac check in GCM failed" error. This issue appears to be size-specific, as files of other sizes download correctly.
Error Details
Copy[17:22:17 ERR] Failed to process restore item. RetryHelper.Value is empty. Failed file bcd074670c64//Users/ajdali/Documents/TestIssue/1000mb.txt
Amazon.Extensions.S3.Encryption.AmazonCryptoException: Failed to decrypt: mac check in GCM failed
---> Org.BouncyCastle.Crypto.InvalidCipherTextException: mac check in GCM failed
at Org.BouncyCastle.Crypto.Modes.GcmBlockCipher.DoFinal(Byte[] output, Int32 outOff) in //crypto/src/crypto/modes/GCMBlockCipher.cs:line 488
at Org.BouncyCastle.Crypto.BufferedAeadBlockCipher.DoFinal(Byte[] output, Int32 outOff) in //crypto/src/crypto/BufferedAeadBlockCipher.cs:line 235
at Org.BouncyCastle.Crypto.BufferedAeadBlockCipher.DoFinal(Byte[] input, Int32 inOff, Int32 inLen) in //crypto/src/crypto/BufferedAeadBlockCipher.cs:line 205
at Org.BouncyCastle.Crypto.IO.CipherStream.ReadAndProcessBlock() in //crypto/src/crypto/io/CipherStream.cs:line 124
at Org.BouncyCastle.Crypto.IO.CipherStream.FillInBuf() in //crypto/src/crypto/io/CipherStream.cs:line 92
at Org.BouncyCastle.Crypto.IO.CipherStream.Read(Byte[] buffer, Int32 offset, Int32 count) in //crypto/src/crypto/io/CipherStream.cs:line 72
at Amazon.Extensions.S3.Encryption.Util.AesGcmDecryptStream.Read(Byte[] buffer, Int32 offset, Int32 count)
Reproduction Steps
Steps to Reproduce
Upload a file that is exactly 1GB (1000MB) to S3 with client-side encryption enabled
Attempt to download and decrypt the file using Amazon.Extensions.S3.Encryption
Observe the "mac check in GCM failed" error
AWS .NET SDK and/or Package version used
AWS SDKs for .NET used:
PackageReference Include="AWSSDK.Core" Version="3.7.302"
PackageReference Include="AWSSDK.S3" Version="3.7.305.17"
PackageReference Include="AWSSDK.SecurityToken" Version="3.7.103.14"
PackageReference Include="Amazon.Extensions.S3.Encryption" Version="2.1.0"
Targeted .NET Platform
net6.0-macos
Operating System and version
macOS 15.4