Skip to content

fix(storage): refuse reads of files whose upload is not complete - #14876

Merged
HarshMN2345 merged 1 commit into
mainfrom
fix-file-scan-before-read
Oct 23, 2026
Merged

HarshMN2345 merged 1 commit into
mainfrom
fix-file-scan-before-read

Conversation

@HarshMN2345

Copy link
Copy Markdown
Member

Download, view, preview and push file routes (including token access, which goes through the same routes) now return storage_file_not_found while chunksUploaded < chunksTotal, i.e. until the final chunk has been joined and scanned. No schema change.

Details are tracked internally.

Tested: PHP syntax check on the touched files; CI e2e for Storage.

@luxor-code-review

luxor-code-review Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This change makes the four file-serving endpoints treat a file as not found until its final chunk has been uploaded and joined, preventing clients from reading a partially assembled file. The check mirrors the existing isEmpty() guard in each endpoint.

Files Change
src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/{Download,Preview,Push,View}/Get.php Adds chunksUploaded < chunksTotal to the existing not-found guard, with a comment explaining the join-and-scan lifecycle.

No issues were identified in the reviewed code paths.

Reviewed commit: 80f45cc

@ghost

ghost commented Oct 23, 2026 •

Copy link
Copy Markdown

🔵 Tier A · Mergeable after minor fixes

The implementation is straightforward, but the new pending-file access behavior needs an E2E regression test.

The Storage download, view, preview, and push routes now check upload chunk counters before accessing file content. Files remain unavailable through these routes until all chunks are uploaded and finalization has completed.

Verdict New comments Fixed Still open
✅ Approved 1 0 0
Finding Where
🟡 Cover pending-file reads in Storage E2E tests src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Download/Get.php:122
Fix with agent prompt
### Issue 1
src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Download/Get.php:122
**Cover pending-file reads in Storage E2E tests**

The Storage E2E suite exercises partial uploads and completed-file reads, but does not attempt these content routes against a pending file. Add coverage that leaves a chunk outstanding and verifies the download, view, preview, and push routes (including token access) return `storage_file_not_found`, so this completion gate cannot regress unnoticed.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
📂 Walkthrough · 4
File Change
src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Download/Get.php Rejects downloads of files whose uploaded chunk count is incomplete.
src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php Rejects previews of files whose uploaded chunk count is incomplete.
src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Push/Get.php Rejects push reads of files whose uploaded chunk count is incomplete.
src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/View/Get.php Rejects views of files whose uploaded chunk count is incomplete.

Reviewed 80f45cc · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Tier A · Looks good to merge. Summary


if ($file->isEmpty()) {
// A file stays incomplete until its final chunk is joined and scanned.
if ($file->isEmpty() || $file->getAttribute('chunksUploaded', 0) < $file->getAttribute('chunksTotal', 1)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cover pending-file reads in Storage E2E tests

The Storage E2E suite exercises partial uploads and completed-file reads, but does not attempt these content routes against a pending file. Add coverage that leaves a chunk outstanding and verifies the download, view, preview, and push routes (including token access) return storage_file_not_found, so this completion gate cannot regress unnoticed.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Download/Get.php
Line: 122

Comment:
**Cover pending-file reads in Storage E2E tests**

The Storage E2E suite exercises partial uploads and completed-file reads, but does not attempt these content routes against a pending file. Add coverage that leaves a chunk outstanding and verifies the download, view, preview, and push routes (including token access) return `storage_file_not_found`, so this completion gate cannot regress unnoticed.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

🟡 Minor · testing · Reply if this doesn't apply.

@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

6 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (3)
  • php.appwrite.secret-compare-timing (1)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@github-actions

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix-file-scan-before-read (after).

Metric Before After Change
🚀 Requests/sec 206.48 216.96 🟢 +5.1%
⏱️ Latency P50 82.11 ms 78.18 ms ⚪ -4.8%
⏱️ Latency P95 201.38 ms 195.88 ms ⚪ -2.7%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 78.18 195.88 13,680 216.96 -5.5
Account 162.34 295.9 720 12.19 +3.62
TablesDB 74.79 142.13 7,440 121.94 -29.01
Storage 72.81 169.39 3,600 59.91 -3.07
Functions 125.43 239.78 1,920 32.5 +14.67

Top API waits (after)

API request Max wait (ms)
account.prefs.update 461.9
account.name.update 427.17
functions.create 398.36
functions.variables.delete 353.26
tablesdb.rows.create 353.23

@HarshMN2345
HarshMN2345 merged commit 73b71a6 into main Oct 23, 2026
42 checks passed
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
View, download, preview and push served a file before its final chunk was joined and scanned. They now answer file not found until every chunk is uploaded.

(cherry picked from commit 73b71a6)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
View, download, preview and push served a file before its final chunk was joined and scanned. They now answer file not found until every chunk is uploaded.

(cherry picked from commit 73b71a6)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
View, download, preview and push served a file before its final chunk was joined and scanned. They now answer file not found until every chunk is uploaded.

(cherry picked from commit 73b71a6)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
View, download, preview and push served a file before its final chunk was joined and scanned. They now answer file not found until every chunk is uploaded.

(cherry picked from commit 73b71a6)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
View, download, preview and push served a file before its final chunk was joined and scanned. They now answer file not found until every chunk is uploaded.

(cherry picked from commit 73b71a6)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
View, download, preview and push served a file before its final chunk was joined and scanned. They now answer file not found until every chunk is uploaded.

(cherry picked from commit 73b71a6)
Tapraj-Pathak pushed a commit to Tapraj-Pathak/appwrite that referenced this pull request Oct 24, 2026
…read

fix(storage): refuse reads of files whose upload is not complete

(cherry picked from commit 73b71a6)
ChiragAgg5k added a commit that referenced this pull request Oct 24, 2026
1.9.10 refuses reads of incomplete uploads (#14876); a preview cached before the upgrade would otherwise still be served on a cache hit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant