Repository navigation
fix(storage): check preview limit against original file size - #14284
Conversation
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.
|
Review complete. No issues found — approved ✅. This one-line change corrects the preview endpoint's oversized-file guard by comparing against
No issues were found in review; the change is minimal and semantically correct. Reviewed commit: e462c73 |
🔵 Tier A · Mergeable after minor fixes
The preview endpoint now enforces
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
⏳ Still open from earlier reviews · 1
Merged |
| $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)) { |
There was a problem hiding this 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.
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.
Security rulesNo new WARNING or ERROR findings from security rules. 32 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)
|
What does this PR do?
GET /v1/storage/buckets/:bucketId/files/:fileId/previewcomparedsizeActualagainst_APP_STORAGE_PREVIEW_LIMIT. Files of 20 MB or less in encrypted buckets are stored as base64 (OpenSSL::encryptwith options0), sosizeActualis 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=400on cache misses:sizeOriginal)sizeActual(encrypted)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