Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Allow space in-between checksums in response headers #169

@mcsimps2

Description

@mcsimps2

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

Metadata

Metadata

Assignees

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.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