Skip to content

Commit

Permalink
WebHost: Prevent committing data packages with invalid checksums to d…
Browse files Browse the repository at this point in the history
…atabase and prevent 500 error from invalid `zip` files.
  • Loading branch information
ThePhar committed Apr 24, 2024
1 parent cca9778 commit fb96369
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions WebHostLib/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ def process_multidata(compressed_multidata, files={}):
game_data = games_package_schema.validate(game_data)
game_data = {key: value for key, value in sorted(game_data.items())}
game_data["checksum"] = data_package_checksum(game_data)
game_data_package = GameDataPackage(checksum=game_data["checksum"],
data=pickle.dumps(game_data))
if original_checksum != game_data["checksum"]:
raise Exception(f"Original checksum {original_checksum} != "
f"calculated checksum {game_data['checksum']} "
f"for game {game}.")

game_data_package = GameDataPackage(checksum=game_data["checksum"],
data=pickle.dumps(game_data))
decompressed_multidata["datapackage"][game] = {
"version": game_data.get("version", 0),
"checksum": game_data["checksum"],
Expand Down Expand Up @@ -192,6 +193,8 @@ def uploads():
res = upload_zip_to_db(zfile)
except VersionException:
flash(f"Could not load multidata. Wrong Version detected.")
except Exception as e:
flash(f"Could not load multidata. File may be corrupted or incompatible. ({e})")
else:
if res is str:
return res
Expand Down

0 comments on commit fb96369

Please sign in to comment.