Skip to content
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

Allow space in-between checksums in response headers #169

Closed
mcsimps2 opened this issue Sep 8, 2020 · 0 comments · Fixed by #170
Closed

Allow space in-between checksums in response headers #169

mcsimps2 opened this issue Sep 8, 2020 · 0 comments · Fixed by #170
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@mcsimps2
Copy link
Contributor

mcsimps2 commented Sep 8, 2020

Summary: I encountered this bug when downloading files using the Google Cloud Storage Python libraries, but the bug is coming from the Resumable Media library. The current code (and official docs) assumes the checksum headers will be contiguous without whitespace:

'x-goog-hash': 'crc32c=t6zgHw==,md5=zH3E9XwJPGGra4vnT+aamQ=='

However, I'm actually getting responses with whitespaces between each type of checksum:

'x-goog-hash': 'crc32c=t6zgHw==, md5=zH3E9XwJPGGra4vnT+aamQ=='

Because of this, the checksum of downloaded files aren't being verified.

Solution is to patch _helpers.py as follows:

def _parse_checksum_header(header_value, response, checksum_label):
    if header_value is None:
        return None

    matches = []
    for checksum in header_value.split(u","):
        name, value = checksum.split(u"=", 1)
        # Use lstrip to support both "," and ", " as delimiters
        if name.lstrip() == checksum_label:
            matches.append(value)

    if len(matches) == 0:
        return None
    elif len(matches) == 1:
        return matches[0]
    else:
        raise common.InvalidResponse(
            response,
            u"X-Goog-Hash header had multiple ``{}`` values.".format(checksum_label),
            header_value,
            matches,
        )

Relevant: #22, #31, #32

mcsimps2 added a commit to mcsimps2/google-resumable-media-python that referenced this issue Sep 8, 2020
The current checksum logic only allowed checksum headers in the format "crc32c=hash1,md5=hash2", but GCP may actually return them with a space in-between as "crc32c=hash1, md5=hash2".

Resolves googleapis#169
mcsimps2 added a commit to mcsimps2/google-resumable-media-python that referenced this issue Sep 8, 2020
The current checksum logic only allowed checksum headers in the format "crc32c=hash1,md5=hash2", but GCP may actually return them with a space in-between as "crc32c=hash1, md5=hash2".

Resolves googleapis#169
mcsimps2 added a commit to mcsimps2/google-resumable-media-python that referenced this issue Sep 8, 2020
The current checksum logic only allowed checksum
 headers in the format "crc32c=hash1,md5=hash2",
 but GCP may actually return them with a space
 in-between as "crc32c=hash1, md5=hash2".

Resolves googleapis#169
@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Sep 9, 2020
@busunkim96 busunkim96 added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. and removed triage me I really want to be triaged. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Sep 9, 2020
crwilcox added a commit that referenced this issue Sep 10, 2020
The current checksum logic only allowed checksum
 headers in the format "crc32c=hash1,md5=hash2",
 but GCP may actually return them with a space
 in-between as "crc32c=hash1, md5=hash2".

Resolves #169

Co-authored-by: Christopher Wilcox <crwilcox@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants