Skip to content

feat(Storage): Enable full object checksum validation for resumable uploads#15395

Open
mahendra-google wants to merge 1 commit intogoogleapis:mainfrom
mahendra-google:enable-json-full-object-checksums
Open

feat(Storage): Enable full object checksum validation for resumable uploads#15395
mahendra-google wants to merge 1 commit intogoogleapis:mainfrom
mahendra-google:enable-json-full-object-checksums

Conversation

@mahendra-google
Copy link
Contributor

This PR enables full object checksum validation (specifically CRC32C) for JSON-based resumable uploads, ensuring end-to-end data integrity for multi-chunk transfers. Please see b/461996128

@mahendra-google mahendra-google requested review from a team January 21, 2026 10:57
@product-auto-label product-auto-label bot added the api: storage Issues related to the Cloud Storage API. label Jan 21, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @mahendra-google, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces robust data integrity checks for resumable uploads by integrating CRC32C checksum validation. This enhancement ensures that multi-chunk transfers to Google Cloud Storage are verified end-to-end, preventing data corruption. The changes also update the client's error handling to align with the server's response to checksum mismatches.

Highlights

  • Enabled CRC32C Checksum Validation: Implemented end-to-end CRC32C checksum validation for JSON-based resumable uploads, ensuring data integrity for multi-chunk transfers.
  • Updated Upload Validation Behavior: Modified integration tests to reflect the new behavior where invalid checksums during resumable uploads now result in a GoogleApiException with a BadRequest status, indicating server-side rejection.
  • Enhanced Stream Handling for Checksum Calculation: Improved the LengthOnlyStream implementation to support seeking and reading, which is crucial for calculating the full CRC32C hash of the stream before the final chunk is sent.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enables full object checksum validation for resumable uploads by introducing a Crc32cHashInterceptor. This interceptor calculates the CRC32C hash of the upload stream and attaches it to the final chunk of a resumable upload, ensuring end-to-end data integrity. The implementation is solid, with proper handling of the interceptor's lifecycle. The integration tests have been correctly updated to reflect the new server-side validation behavior, where the server now rejects corrupted uploads with a BadRequest status. Additionally, LengthOnlyStream has been updated to be a more compliant Stream implementation. My review includes a couple of suggestions to optimize performance by avoiding string allocations in the new parsing logic.

Choose a reason for hiding this comment

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

Adding this globally to the http client which is not ideal. Every single request GET, LIST, DELETE made by this client must now run through the URI check in InterceptAsync. Also if there is an exception and if OnProgressChanged is not triggered, the interceptor stays in the client forever.

Choose a reason for hiding this comment

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

On the final chunk, you are calculating the hash for entire stream which could be in Gbs. This will cause a performance regression for huge data. Incase of retries, this logic will be computed multiple times again

Choose a reason for hiding this comment

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

You're not checking if the user has disabled this (using UploadValidationMode.None) crc32c validation here.

Choose a reason for hiding this comment

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

I think you are modifying the global stream's position here which could be a side effect. If this stream is used concurrently somewhere, that could lead to an issue

@krishnamd-jkp
Copy link

Can you use UploadStreamInterceptor which already calculates the hash and use it here instead of recomputing the hash on final chunk?

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 Cloud Storage API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants