Skip to content

Commit

Permalink
Surround decompression with try..catch + strip ".gz" from filename (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
shurivich authored Jan 12, 2025
1 parent 0d3c7ea commit a7eed9c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions utils/proxy/_deserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,12 @@ def json_load():
item["content"] = json.loads(part.content)

elif content_type_part == "application/gzip":
with gzip.GzipFile(fileobj=io.BytesIO(part.content)) as gz_file:
content = gz_file.read()
try:
with gzip.GzipFile(fileobj=io.BytesIO(part.content)) as gz_file:
content = gz_file.read()
except:
item["system-tests-error"] = "Can't decompress gzip data"
continue

_deserialize_file_in_multipart_form_data(item, headers, export_content_files_to, content)

Expand Down Expand Up @@ -239,6 +243,8 @@ def _deserialize_file_in_multipart_form_data(
item["system-tests-error"] = "Filename not found in content-disposition, please contact #apm-shared-testing"
else:
filename = meta_data["filename"].strip('"')
if filename.lower().endswith(".gz"):
filename = filename[:-3]
file_path = f"{export_content_files_to}/{md5(content).hexdigest()}_{filename}"

with open(file_path, "wb") as f:
Expand Down

0 comments on commit a7eed9c

Please sign in to comment.