Repository navigation
fix(storage): reject chunks whose Content-Range total differs from the first - #14514
Conversation
…e first Every chunk after the first must announce the size stored by the first chunk; a different total is rejected with storage_invalid_content_range instead of silently completing a truncated file or leaving it pending forever. A chunked file whose merged size differs from the announced size is removed and rejected too. Function and site deployment uploads get the same total check.
|
Review complete. 🟡 1 medium 📍 Findings outside the diff (1) — 🟡 1 medium — defects on lines GitHub can't attach comments to🟡 Medium — Finalize size check missing in Functions/Sites · src/Appwrite/Platform/Modules/Functions/Http/Deployments/Create.php The PR's goal — reject uploads whose assembled bytes diverge from the announced Content-Range total — is enforced only in Storage, where after This PR hardens chunked uploads by checking that the assembled file's real size matches the announced
Reviewed commit: 93b47fc |
🟢 Tier S · Ready to mergeThe pull request validates resumed Content-Range totals and checks that finalized upload sizes match the announced size for Storage files and Function/Site deployments. Invalid Storage uploads are removed, while invalid deployments are marked failed and retained so retries return the failed deployment. E2E coverage exercises the size-mismatch handling across all three upload surfaces. Latest changes: The newest commits add Function and Site E2E tests for short final chunks, checking the 400 response, persisted failed status, and retry behavior.
📂 Walkthrough · 6
✅ Fixed since the last review · 1
Reviewed the commits since |
Security rulesNo new WARNING or ERROR findings from security rules. 19 existing findings tracked in
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
…rom its range Functions and sites deployments now get the same post-merge size check as storage files: the source is removed and the deployment marked failed. Adds e2e coverage for a changed total and a short final chunk.
Chunked uploads parsed the
Content-Rangetotal from every chunk but never compared it with the size the first chunk stored, so a chunk with a different total could complete a truncated file, leave a file pending forever with orphaned parts, or decide compression/encryption/antivirus from the wrong size.sizeOriginalis rejected withstorage_invalid_content_range(400), after the resume permission check and before the completed-file short-circuit.sourceSize, after the resource ownership check.failedwith the reason inbuildLogs(kept rather than deleted, since a site's first chunk already created its rule). It is marked fully uploaded, so a retried chunk returns the failed deployment instead of writing to the removed source.Behaviour change: retrying the last chunk of a finished upload with a different total now returns 400 instead of the completed file.
Verified
On a local stack (Postgres, Redis, API, worker):
storage_invalid_content_rangefailedwith the reason inbuildLogs; no source left; retrying the chunk returns the failed deployment (202)sourceSizeboth exactly 5,243,904 bytestestChunkedUploadRejectsChangedTotalandtestChunkedUploadRejectsShortChunk:OK (2 tests, 18 assertions).testCreateDeploymentRejectsShortChunkfor functions (OK (1 test, 19 assertions)) and sites (OK (1 test, 24 assertions)): 400, deploymentfailed, a retried chunk returns the failed deployment.StorageCustomServerTest(out-of-order, parallel, large file, antivirus) pass;StorageCustomClientTestpasses (42 tests, 974 assertions).pint --testandphpstan analyseon the changed files.Closes #14475