Skip to content

Invalid data returned from "InputStream.read()" on an empty S3 Object #3538

Open
@youngm

Description

Describe the bug

I have an empty S3 object. When I create an InputStream to that object and invoke "read()" I get back an int "212".

Expected Behavior

I would expect InputStream.read() to an empty S3Object to return -1.

Current Behavior

Currently it returns a single byte 212.

Reproduction Steps

When executed against a 0 byte (empty) S3Object the following code returns 212. It should return -1

      var getObjectRequest =
          GetObjectRequest.builder()
              .bucket("bucket")
              .key(
                  "emptyobject")
              .build();
      try (var fileContent =
          s3Client.getObject(getObjectRequest, ResponseTransformer.toInputStream())) {
        System.out.println(fileContent.read());
      }

Possible Solution

I don't know but the problem appears to be in the software.amazon.awssdk.services.s3.checksums.ChecksumValidatingInputStream class. That is where the result diverges from using something like InputStream.readAllBytes().

Additional Information/Context

No response

AWS Java SDK version used

2.17.283

JDK version used

17

Operating System and version

Windows 11

Activity

added
bugThis issue is a bug.
needs-triageThis issue or PR still needs to be triaged.
on Nov 7, 2022
youngm

youngm commented on Nov 8, 2022

@youngm
Author

FWIW, seems to work fine with a 1 byte object. Only empty files are a problem.

changed the title Invalid data returned when "read()"ing an empty S3 Object Invalid data returned with "InputStream.read()" on an empty S3 Object on Nov 8, 2022
changed the title Invalid data returned with "InputStream.read()" on an empty S3 Object Invalid data returned from "InputStream.read()" on an empty S3 Object on Nov 8, 2022
self-assigned this
on Nov 8, 2022
yasminetalby

yasminetalby commented on Nov 9, 2022

@yasminetalby

Hello @youngm ,

Thank you very much for your submission and for bringing this up to our attention. I was able to reproduce and confirm the behavior with the latest version of the SDK and will bring this up to the team for review.
I was wondering if you were encountering any blockers or limitation due to this?

Best regards,

Yasmine

youngm

youngm commented on Nov 9, 2022

@youngm
Author

@yasminetalby No, I have been able to work around the issue for now on my side. Thanks for asking and picking up the issue!

yasminetalby

yasminetalby commented on Nov 9, 2022

@yasminetalby

Of course. Thank you very much for bringing up this behavior to our attention, your feedback is very valuable to the team.
I am glad to hear that you have been able to workaround the issue. I will post all updates regarding this in the comment section.

Best regards,

Yasmine

added
needs-reviewThis issue or PR needs review from the team.
p3This is a minor priority issue
p2This is a standard priority issue
and removed
needs-reviewThis issue or PR needs review from the team.
p3This is a minor priority issue
on Nov 9, 2022

11 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.p2This is a standard priority issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Invalid data returned from "InputStream.read()" on an empty S3 Object · Issue #3538 · aws/aws-sdk-java-v2