GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — BlobWriteChannel CRC32C and MD5 hash mismatch error · Issue #267 · googleapis/google-cloud-java

BlobWriteChannel CRC32C and MD5 hash mismatch error #267

New issue
Copy link
New issue
Copy link
Closed
#271
Closed
BlobWriteChannel CRC32C and MD5 hash mismatch error#267
#271
Copy link
Assignees
mziccard
Labels
🚨 criticalP0 critical issue. Requires immediate fixapi: storageIssues related to the Cloud Storage API.triage meI really want to be triaged.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Description

@mziccard
mziccard
opened on Oct 16, 2015
Issue body actions

The following code:

BlobId blobId = BlobId.of("bucket", "blob_name");
BlobInfo blobInfo = BlobInfo.builder(blobId).contentType("test/plain").build();
storage.create(blobInfo, "Hello, Cloud Storage!".getBytes(UTF_8));
BlobInfo updatedBlobInfo = storage.get(blobId);
WritableByteChannel channel = storage.writer(updatedBlobInfo);
channel.write(ByteBuffer.wrap("Updated content".getBytes(UTF_8)));
channel.close();

causes an error:

Caused by: com.google.gcloud.storage.StorageException: 400 Bad Request
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalid",
"message": "Provided CRC32C "IgKckQ==" doesn't match calculated CRC32C "c5cgUw=="."
},
{
"domain": "global",
"reason": "invalid",
"message": "Provided MD5 hash "paCw+9t7LhjISSAPBaeazA==" doesn't match calculated MD5 hash "SFCAEvYjPzpCjkKQr6MGGg=="."
}
],
"code": 400,
"message": "Provided CRC32C "IgKckQ==" doesn't match calculated CRC32C "c5cgUw=="."
}
}

If a stale BlobInfo object is passed to storage.writer(blobInfo) instead:

// ...
BlobInfo blobInfo = BlobInfo.builder(blobId).contentType("test/plain").build();
storage.create(blobInfo, "Hello, Cloud Storage!".getBytes(UTF_8));
WritableByteChannel channel = storage.writer(blobInfo);
channel.write(ByteBuffer.wrap("Updated content".getBytes(UTF_8)));
channel.close();

No error occurs.

It seems to me that if a "complete" StorageObject is passed to DefaultStorageRpc.open then its md5Hash and crc32c fields are used to request the upload id (see this line). At the end of the upload if that data do not match with the uploaded one the whole upload fails.
Do you think this is a desirable default behavior?
I think it is not, I would rather add some options to storage.writer(...) to allow users to explicitly choose to check md5Hash and crc32c if they have already computed them and put them into the BlobInfo object (i.e. if they know what they're doing).
Thoughts?

Activity

Next
  1. mziccard
    added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    api: storageIssues related to the Cloud Storage API.
    on Oct 16, 2015
  2. mziccard
    self-assigned this
    on Oct 16, 2015
  3. aozarov commented on Oct 16, 2015

    @aozarov
    aozarov
    on Oct 16, 2015
    Contributor
    More actions

    Good catch!

    Yes. GCS does use consider crc32c and md5Hash for insert operation and use it to validate
    the content upon completion.

    I think this is a tricky one as one might not expect it, like in the usage pattern you described.
    However, some users may want to take advantage of this feature in order to verify the uploads.

    We could document this behavior in the Java doc (and add a code snippet showing how to clear the 2 fields if BlobInfo was not manually constructed and the validation is undesired) but I think this is even
    trickier when one is using Blob.writer...

    Another way to deal with it can be to have a separate set of options to writer.
    By default, we will ignore the 2 fields unless requested via an option.

    Thoughts?

    /cc @BrandonY

  4. aozarov commented on Oct 16, 2015

    @aozarov
    aozarov
    on Oct 16, 2015
    Contributor
    More actions

    Actually, this issue also applied to create methods.
    In the case of create we should probably "reset" the md5 and crc to reflect the byte[] or empty but
    we still have an issue with the newly added method that accepts an InputStream.
    Maybe that create should also use the write options...

  5. aozarov commented on Oct 16, 2015

    @aozarov
    aozarov
    on Oct 16, 2015
    Contributor
    More actions

    Another option (not sure if I like it that much) is to have a "special" method on BlobInfo and Blob that is basically a syntactic sure for toBuilder().md5(null).crc32c(null).build().

    Any other suggestions we welcomed!

  6. mziccard commented on Oct 18, 2015

    @mziccard
    mziccard
    on Oct 18, 2015
    ContributorAuthor
    More actions

    My preferred option is to handle this with options:D
    I would add a BlobWriteOptions which has the same static methods as BlobTargetOptions and also:

    md5HashMatch()
    crc32cMatch()

    And we make create and write accept a BlobWriteOptions instead of BlobTargetOptions. If those options are specified we pass on md5Hash and crc32c to RPC's StorageObject, otherwhise we set them to null (to prevent the error this issue refers to).
    This seems to me the "less unexpected" behaviour. But I am open for suggestions!

  7. aozarov commented on Oct 19, 2015

    @aozarov
    aozarov
    on Oct 19, 2015
    Contributor
    More actions

    Yes, that is my prefered option too (though I would also suggest to keep the BlobWriteOptions and reset the crc32c and md5 for the empty create and the create with byte[]).

  8. mziccard commented on Oct 19, 2015

    @mziccard
    mziccard
    on Oct 19, 2015
    ContributorAuthor
    More actions

    Makes perfectly sense

  9. aozarov
    closed this as completedin #271on Oct 20, 2015
  10. yoshi-automation
    added
    🚨 criticalP0 critical issue. Requires immediate fix
    triage meI really want to be triaged.
    on Apr 6, 2020
  11. github-actions
    added 3 commits that reference this issue on Jun 29, 2022

    ci(java): suggest formatting fixes (googleapis#267)

    26d45d0

    chore: update dependencies for regapic (googleapis#1467) (googleapis#267

    4fbef60

    feat: promote to 1.0.0 (#267)

    57f9b08
  12. 15 remaining items

  13. github-actions
    added 2 commits that reference this issue on Oct 6, 2022

    chore(deps): update dependency com.google.cloud:google-cloud-debugger…

    f839c4d

    chore: [java] generation with shared deps 3.0.4 (#1641) (#267)

    ff3bd29
  14. github-actions
    added 2 commits that reference this issue on Nov 8, 2022

    chore(java): add a note in README for migrated split repos (googleapi…

    40a9f3a

    chore(java): add a note in README for migrated split repos (googleapi…

    a64f40b
  15. meltsufin
    added a commit that references this issue on Dec 22, 2025

    build: rename samples lint workflow to checkstyle to disambiguate bra…

    bd04fbb
  16. chingor13
    added a commit that references this issue on Jan 6, 2026

    chore: regenerate README (#267)

    e21b1b2
  17. chingor13
    added a commit that references this issue on Jan 22, 2026

    chore: regenerate README (#267)

    517b0ec
  18. chingor13
    added a commit that references this issue on Feb 24, 2026

    Add credentials for autorelease (#267)

    1091092
  19. suztomo
    added a commit that references this issue on Mar 11, 2026

    build: rename samples lint workflow to checkstyle to disambiguate bra…

    2abd9ce
  20. chingor13
    added a commit that references this issue on Mar 12, 2026

    Add credentials for autorelease (#267)

    b6d71c4
  21. suztomo
    added a commit that references this issue on Mar 30, 2026

    chore(deps): update dependency com.google.cloud:libraries-bom to v13.…

    94ebdbf
  22. lqiu96
    added a commit that references this issue on Apr 1, 2026

    chore(deps): update dependency com.google.cloud:libraries-bom to v13.…

    8524854
  23. meltsufin
    added 2 commits that reference this issue on Apr 29, 2026

    feat: Send streaming pull flow control settings to server (#267)

    9c750c8

    feat: Send streaming pull flow control settings to server (#267)

    04b4bcf
  24. benjaminp
    added a commit that references this issue on Jul 13, 2026

    deps: update dependency io.grpc:grpc-bom to v1.29.0 (googleapis#267)

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

Metadata

Metadata

Assignees

  • @mziccard
    mziccard

Labels

🚨 criticalP0 critical issue. Requires immediate fixapi: storageIssues related to the Cloud Storage API.triage meI really want to be triaged.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.