Throw Crc32MismatchException when response content is absent but x-amz-crc32 is present and is non-zero, instead of silently returning an empty response#6978
Merged
Conversation
…z-crc32 is present and is non-zero, instead of silently returning an empty response.
d105e7a to
7fb22f6
Compare
zoewangg
approved these changes
May 19, 2026
| jsonRpc.allTypes(AllTypesRequest.builder().build()); | ||
| } | ||
|
|
||
| @Test(expected = Crc32MismatchException.class) |
Contributor
There was a problem hiding this comment.
Can we use assertThatThrowsBy instead
Contributor
Author
There was a problem hiding this comment.
Done ..Also updated other instances of expected = in this class
| client.allTypes(AllTypesRequest.builder().build()); | ||
| } | ||
|
|
||
| @Test(expected = Crc32MismatchException.class) |
Contributor
There was a problem hiding this comment.
Can we use assertThatThrowsBy instead
|
This pull request has been closed and the conversation has been locked. Comments on closed PRs are hard for our team to see. If you need more assistance, please open a new issue that references this one. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
When an AWS service returns a response with a non-zero
x-amz-crc32header but the response content is not delivered to the SDK, the v2 SDK silently passed the response through to the caller as an empty result. This means that if the service computed a checksum over a response body but the body bytes never reached the SDK (for example because the body was cleared, emptied, or corrupted by an intermediary), the corruption goes undetected and the caller sees what looks like a valid empty response.The v1 SDK already handles this case correctly. In
JsonResponseHandler.handle(...), validation runs whenever thex-amz-crc32header is present, comparing the server-side value againstresponse.getCRC32Checksum(). The companionHttpResponse.getCRC32Checksum()r which returns0Lwhen no response body is available (CRC32 of empty bytes is0). When the server-side value is non-zero, the comparison fails andCRC32MismatchExceptionis thrown. This makes the failure visible and retryable.This change brings v2 to behavioral parity with v1 so that integrity failures are surfaced rather than silently returning empty responses, and the request can be retried.
Modifications
Added a check in
Crc32Validation.validate(...)to throwCrc32MismatchExceptionwhen content is absent andx-amz-crc32is non-zero. Header value of0still passes through (CRC32 of empty bytes is0).Testing
License