KEMBAR78
fix: Add an exception to zero byte uploads on CreateFrom by JesseLovelace · Pull Request #2342 · googleapis/java-storage · GitHub
Skip to content

Conversation

@JesseLovelace
Copy link
Contributor

@JesseLovelace JesseLovelace commented Dec 28, 2023

This PR introduced a bug in using createFrom to upload a zero byte object. I can't figure out where exactly the bug is, but something is causing the content range to be 0-1 instead of 0-0 in this case. It ends up getting rejected because the range is bigger than the content size, which is still zero.

We can fix the bug later when we identify the root cause, but for now I'm just reverting to the old way of doing it when we detect that we're uploading a zero byte file.

I also added a test for this case

@JesseLovelace JesseLovelace requested a review from a team as a code owner December 28, 2023 00:27
@product-auto-label product-auto-label bot added size: s Pull request size is small. api: storage Issues related to the googleapis/java-storage API. labels Dec 28, 2023
@BenWhitehead
Copy link
Collaborator

Fix looks well to me. In fact skipping creating a resumable session at all is a good call when the object is empty.

My guess is the error is actually a Content-Range header value of 0--1/0 (zero to -1 of zero). Which is calculated based on the 0 being passed in for size here

HttpContentRange contentRange =
HttpContentRange.of(ByteRangeSpec.relativeLength(0L, size), size);

Thanks for the fix @JesseLovelace

@JesseLovelace JesseLovelace merged commit 2b5b27e into main Jan 2, 2024
@JesseLovelace JesseLovelace deleted the fixzerobyte branch January 2, 2024 18:18
JesseLovelace added a commit that referenced this pull request Jan 22, 2024
* fix: Add an exception to zero byte uploads on CreateFrom

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
JesseLovelace added a commit that referenced this pull request Jan 22, 2024
* fix: Add an exception to zero byte uploads on CreateFrom

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: storage Issues related to the googleapis/java-storage API. size: s Pull request size is small.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants