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

Handle older S3 packages for operations that require MD5 or checksums #3642

Merged
merged 2 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"core": {
"updateMinimum": true,
"type": "Patch",
"changeLogMessages": [
"Update data integrity component to handle older versions of the `AWSSDK.S3` package when operations require a `Content-MD5` header"
]
}
}
8 changes: 7 additions & 1 deletion sdk/src/Core/Amazon.Runtime/Internal/Util/ChecksumUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,13 @@ public static void SetChecksumData(IRequest request, string checksumAlgorithm, b
// S3 does not support).

// TODO: Similar to "SetRequestChecksum", this method should be removed in V4.
if (!string.IsNullOrEmpty(checksumAlgorithm))
if (fallbackToMD5)
{
// Reported in https://github.com/aws/aws-sdk-net/issues/3641
// Some operations will fail if the Content-MD5 header is not set, so we need to set it to maintain backwards compatibility.
SetChecksumData(request);
}
else if (!string.IsNullOrEmpty(checksumAlgorithm))
{
SetChecksumData(request, checksumAlgorithm, fallbackToMD5, isRequestChecksumRequired: true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,20 @@ public void WriteToRequestBody(HttpContent requestContent, Stream contentStream,
if ((isChunkedUploadWrapperStreamWithLength || isTrailingHeadersWrapperStreamWithLength || isCompressionWrapperStreamWithLength)
|| (chunkedUploadWrapperStream == null && trailingHeadersWrapperStream == null && compressionWrapperStream == null))
{
_request.Content.Headers.ContentLength = contentStream.Length - contentStream.Position;
long position;
try
{
position = contentStream.Position;
}
catch (NotSupportedException)
{
// If this method is invoked from an older service package, the content stream may not support getting the
// current position (for example, "MD5Stream" doesn't).
// In this case, we'll assume the position is 0 to maintain the previous behavior.
position = 0;
}

_request.Content.Headers.ContentLength = contentStream.Length - position;
}

WriteContentHeaders(contentHeaders);
Expand Down