Zip upload: reject archives over 500 MB uncompressed

Sums the entries' declared sizes before extracting anything; rubyzip's
own validate_entry_sizes (on by default) catches an entry that inflates
past what it declared.
This commit is contained in:
randy committed 2026-11-12 11:54:49 +01:00
1 parent ca2e67599b
commit 7429e4ae33
2 files changed
+23 -2

No files matched your search

+14
View File
@@ -198,6 +198,20 @@ class AppTest < Minitest::Test
refute_includes names, "readme.txt"
end
def test_zip_whose_contents_exceed_the_size_limit_is_rejected_before_saving_anything
zip_bytes = build_zip("big.gpx" => "x" * 2048)
original = Maptool::App::MAX_ZIP_UNCOMPRESSED
Maptool::App.send(:remove_const, :MAX_ZIP_UNCOMPRESSED)
Maptool::App.const_set(:MAX_ZIP_UNCOMPRESSED, 1024)
response = post_file("/api/gpx", filename: "bomb.zip", content: zip_bytes, content_type: "application/zip", env: logged_in_env)
assert_equal 413, response.status
assert_empty json_body(request.get("/api/gpx/tree"))["children"]
ensure
Maptool::App.send(:remove_const, :MAX_ZIP_UNCOMPRESSED)
Maptool::App.const_set(:MAX_ZIP_UNCOMPRESSED, original)
end
def test_corrupt_zip_is_rejected
response = post_file("/api/gpx", filename: "bad.zip", content: "not a zip", content_type: "application/zip", env: logged_in_env)
assert_equal 400, response.status