Merge pull request #4611 from rommapp/claude/empty-upload-review-fixes

fix(upload): refuse an empty file that declares chunks
This commit is contained in:
Zurdi
2026-09-18 03:46:11 +02:00
committed by GitHub
2 changed files with 13 additions and 6 deletions

View File

@@ -279,11 +279,11 @@ async def start_chunked_upload(
) -> dict:
"""Initiate a chunked ROM upload session."""
# An empty file takes no chunks and goes straight to /complete.
if total_size > 0 and total_chunks == 0:
# Only an empty file takes no chunks, and it goes straight to /complete.
if (total_size == 0) != (total_chunks == 0):
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="A non-empty file needs at least one chunk",
detail="Chunk count does not match the file size",
)
db_platform = db_platform_handler.get_platform(platform_id)

View File

@@ -162,18 +162,25 @@ def test_upload_empty_file_without_chunks(
assert final_file.read_bytes() == b""
def test_start_non_empty_file_without_chunks_returns_400(
@pytest.mark.parametrize(("total_size", "total_chunks"), [(11, 0), (0, 2)])
def test_start_with_chunks_that_do_not_match_the_size_returns_400(
client: TestClient,
access_token: str,
platform: Platform,
upload_fs: dict,
total_size: int,
total_chunks: int,
):
response = _start_upload(
client, access_token, platform.id, total_size=11, total_chunks=0
client,
access_token,
platform.id,
total_size=total_size,
total_chunks=total_chunks,
)
assert response.status_code == status.HTTP_400_BAD_REQUEST
assert response.json()["detail"] == "A non-empty file needs at least one chunk"
assert response.json()["detail"] == "Chunk count does not match the file size"
def test_upload_chunk_invalid_upload_id(client: TestClient, access_token: str):