Skip to content

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
joviegas merged 4 commits into
masterfrom
joviegas/crc32_fornocontent_butcrcheader
May 19, 2026
Merged

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
joviegas merged 4 commits into
masterfrom
joviegas/crc32_fornocontent_butcrcheader

Conversation

@joviegas
Copy link
Copy Markdown
Contributor

@joviegas joviegas commented May 19, 2026

Motivation and Context

When an AWS service returns a response with a non-zero x-amz-crc32 header 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 the x-amz-crc32 header is present, comparing the server-side value against response.getCRC32Checksum(). The companion HttpResponse.getCRC32Checksum() r which returns 0L when no response body is available (CRC32 of empty bytes is 0). When the server-side value is non-zero, the comparison fails and CRC32MismatchException is 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 throw Crc32MismatchException when content is absent and x-amz-crc32 is non-zero. Header value of 0 still passes through (CRC32 of empty bytes is 0).

Testing

  • Added Junits

License

  • I confirm that this pull request can be released under the Apache 2 license

@joviegas joviegas requested a review from a team as a code owner May 19, 2026 04:26
@joviegas joviegas added the no-api-surface-area-change Indicate there is no API surface area change and thus API surface area review is not required label May 19, 2026
…z-crc32 is present and is non-zero, instead of silently returning an empty response.
@joviegas joviegas force-pushed the joviegas/crc32_fornocontent_butcrcheader branch from d105e7a to 7fb22f6 Compare May 19, 2026 04:37
jsonRpc.allTypes(AllTypesRequest.builder().build());
}

@Test(expected = Crc32MismatchException.class)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we use assertThatThrowsBy instead

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done ..Also updated other instances of expected = in this class

client.allTypes(AllTypesRequest.builder().build());
}

@Test(expected = Crc32MismatchException.class)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we use assertThatThrowsBy instead

@joviegas joviegas added this pull request to the merge queue May 19, 2026
Merged via the queue into master with commit 146f976 May 19, 2026
13 checks passed
@github-actions
Copy link
Copy Markdown

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.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators May 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

no-api-surface-area-change Indicate there is no API surface area change and thus API surface area review is not required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants