Skip to content

fix(storage): check preview limit against original file size - #14284

Merged
HarshMN2345 merged 3 commits into
mainfrom
fix/storage-preview-original-size
Oct 9, 2026
Merged

HarshMN2345 merged 3 commits into
mainfrom
fix/storage-preview-original-size

Conversation

@HarshMN2345

Copy link
Copy Markdown
Member

What does this PR do?

GET /v1/storage/buckets/:bucketId/files/:fileId/preview compared sizeActual against _APP_STORAGE_PREVIEW_LIMIT. Files of 20 MB or less in encrypted buckets are stored as base64 (OpenSSL::encrypt with options 0), so sizeActual is about 4/3 of the uploaded size. Images between 15 MB and 20 MB in encrypted buckets went over the limit on their stored size and got the grey placeholder with a 200, while the same image in an unencrypted bucket rendered.

The check now uses sizeOriginal, which is what the variable documents ("Maximum file size allowed for file image preview"). Files over 20 MB are never encrypted or compressed, so both sizes are equal for them and nothing changes there. Uploads through the SDKs read at most about 26.7 MB from storage (a 20 MB file after base64).

Existing files don't need re-uploading. Previews already served as placeholders stay in the preview cache until the file's cache entries are cleared.

Test Plan

Ran a local API container with this branch mounted. Uploaded PNGs to an encrypted bucket and an unencrypted one, then requested ?output=webp&width=400 on cache misses:

Image (sizeOriginal) sizeActual (encrypted) Before After
4,994,038 6,658,720 preview preview
16,000,811 21,334,416 placeholder preview
19,703,338 26,271,120 placeholder preview
22,007,813 22,007,813 placeholder placeholder

The unencrypted bucket gave the same results before and after: a preview for the three files under 20 MB and the placeholder for the 22 MB one.

Related PRs and Issues

  • None

Encrypted files are stored base64-encoded, so sizeActual is about 4/3
of the uploaded size. Images between 15 MB and 20 MB in encrypted
buckets exceeded _APP_STORAGE_PREVIEW_LIMIT on their stored size and
got the placeholder image instead of a preview. The limit is documented
as the maximum file size, which is sizeOriginal.
@luxor-code-review

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

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This one-line change corrects the preview endpoint's oversized-file guard by comparing against sizeOriginal instead of sizeActual, which under-measured compressed files and let payloads larger than the intended limit reach the preview pipeline.

Files Change
src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php Uses sizeOriginal in the size-limit check before Imagick transformation; fallback placeholder path is unchanged.

No issues were found in review; the change is minimal and semantically correct.

Reviewed commit: e462c73

@ghost

ghost commented Oct 9, 2026 •

Copy link
Copy Markdown

🔵 Tier A · Mergeable after minor fixes

The behavior change looks correct, but its encrypted-size regression case is not covered by the existing e2e tests.

The preview endpoint now enforces _APP_STORAGE_PREVIEW_LIMIT using the uploaded file's original size rather than its stored size. This allows eligible encrypted images whose base64-encoded representation is larger than the limit to be transformed.

Verdict New comments Fixed Still open
✅ Approved 0 0 1
Fix with agent prompt
### Issue 1
src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php:185
**Add coverage for encrypted files near the preview limit**

Could we add an e2e regression case for an encrypted image whose original size is under the limit but whose encoded stored size exceeds it? Existing preview coverage does not exercise this size check, so reverting to `sizeActual` would not fail a test.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
📂 Walkthrough · 1
File Change
src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php Switched the preview-size check from sizeActual to sizeOriginal.
⏳ Still open from earlier reviews · 1

Merged main (71ae67a); no changes to this PR's code since ad771c7 · 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

$cipher = $file->getAttribute('openSSLCipher');
$mime = $file->getAttribute('mimeType');
if (!\in_array($mime, $inputs) || $file->getAttribute('sizeActual') > (int) System::getEnv('_APP_STORAGE_PREVIEW_LIMIT', APP_STORAGE_READ_BUFFER)) {
if (!\in_array($mime, $inputs) || $file->getAttribute('sizeOriginal') > (int) System::getEnv('_APP_STORAGE_PREVIEW_LIMIT', APP_STORAGE_READ_BUFFER)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Add coverage for encrypted files near the preview limit

Could we add an e2e regression case for an encrypted image whose original size is under the limit but whose encoded stored size exceeds it? Existing preview coverage does not exercise this size check, so reverting to sizeActual would not fail a test.

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

Comment:
**Add coverage for encrypted files near the preview limit**

Could we add an e2e regression case for an encrypted image whose original size is under the limit but whose encoded stored size exceeds it? Existing preview coverage does not exercise this size check, so reverting to `sizeActual` would not fail a test.

---

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

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

32 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (17)
  • php.appwrite.permissive-write-permission (8)
  • php.appwrite.secret-compare-timing (5)
  • 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

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/storage-preview-original-size (after).

Metric Before After Change
🚀 Requests/sec 209.59 206.38 ⚪ -1.5%
⏱️ Latency P50 80.72 ms 84.37 ms ⚪ +4.5%
⏱️ Latency P95 200 ms 195.92 ms ⚪ -2%
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 84.37 195.92 12,882 206.38 -4.08
Account 157.11 298.58 678 11.27 -17.66
TablesDB 82.02 153.27 7,006 114.18 +10.22
Storage 77.05 172.04 3,390 57.27 -10.65
Functions 119.02 235.82 1,808 31.27 -11.7

Top API waits (after)

API request Max wait (ms)
account.name.update 387.1
account.prefs.update 342.72
storage.buckets.create 333.81
functions.variables.create 331.24
functions.variables.update 325.91

@HarshMN2345
HarshMN2345 merged commit 3c66876 into main Oct 9, 2026
6 checks passed
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