Skip to content

Fixed an issue in sync clients where empty response payloads could cause a null pointer exception. #3371

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

Merged
merged 1 commit into from
Aug 23, 2022

Conversation

millems
Copy link
Contributor

@millems millems commented Aug 23, 2022

Before this change, we passed null to response transformers when the HTTP client returned empty. Our built-in response transformers expected non-null, so this would fail. This change passes an empty body to response transformers, instead.

Fixes #3359

…use a null pointer exception.

Before this change, we passed null to response transformers when the HTTP client returned empty. Our built-in response transformers expected non-null, so this would fail. This change passes an empty body to response transformers, instead.
@millems millems requested a review from a team as a code owner August 23, 2022 18:24
@joviegas
Copy link
Contributor

Query , just thinking out loud :
Since this issue is caused by PR #3346 and specific to HttpUrlConnection's handling of HEAD requests.

Why not we create SdkHttpEmptyStream in tryGetInputStream

     private Optional<InputStream> tryGetInputStream() {
            return responseHasNoContent()
                   ? new SdkHttpEmptyStream()
                   : getAndHandle100Bug(() -> invokeSafely(connection::getInputStream), true);
        }

where SdkHttpEmptyStream is emptyInputStream same as HttpURLConnection and then this check in Crc32Validation class

    public static SdkHttpFullResponse validate(boolean calculateCrc32FromCompressedData,
                                               SdkHttpFullResponse httpResponse) {

        if (!httpResponse.content().isPresent() || httpResponse.content() instance of  SdkHttpEmptyStream.class) {
            return httpResponse;
        }

        return httpResponse.toBuilder().content(
            process(calculateCrc32FromCompressedData, httpResponse,
                    httpResponse.content().get())).build();
    }

Since we are overwriting the EmptyInputStream as Optional.empty() in UrlConnectionHttpClient, I think we should pass similar sdk identified SdkEmptyInputStream.

My concern is by handling the Null pointer exception we might mask bugs where Service actually sends a Null content stream ,

@millems
Copy link
Contributor Author

millems commented Aug 23, 2022

The reason I made this change is that HttpExecuteResponse contains an Optional<AbortableInputStream> responseBody, but core fails to handle the case that responseBody is empty. That's clearly a case that needs to get handled by core, regardless of the HTTP client. There's no fixes we could make to the URL connection client to avoid that problem.

We could have "re-hid" the problem by returning an empty stream instead of no stream, but that doesn't feel like fixing the root cause.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

66.7% 66.7% Coverage
0.0% 0.0% Duplication

@millems millems enabled auto-merge (squash) August 23, 2022 19:40
@millems millems merged commit a65355a into master Aug 23, 2022
@millems millems deleted the millem/3359-fix branch October 19, 2022 19:34
aws-sdk-java-automation pushed a commit that referenced this pull request Oct 24, 2024
…-phase1

Releasing CRC64 and checksum refactoring change
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

S3Client fails with exception when executing GetObjectRequest on zero bytes content
3 participants