-
Notifications
You must be signed in to change notification settings - Fork 49
Closed
Labels
priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-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.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Description
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,
)
Metadata
Metadata
Assignees
Labels
priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-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.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.