Repository navigation
fix(storage): stop rejecting clean uploads the scanner could not scan - #13600
Merged
Merged
Conversation
php-clamav 2.0.0 sizes every INSTREAM frame at the fixed chunk length rather than the bytes actually read, and loops on !feof(), which is only true after a read has hit the end. A file is therefore sent roughly doubled and NUL-padded, and the framing desyncs: ClamAV reads file content as a length prefix and answers with an error rather than a verdict. file 1000 bytes -> 2000 bytes sent file 8192 bytes -> 16384 bytes sent file 9192 bytes -> 16384 bytes sent 2.0.1 fixed the framing, 2.0.2 added a result type. Both are taken here. The second half matters on its own. fileScanInStream() answered false for a detection and for a scan that never happened alike, and this acted on the second as the first: it deleted the upload and returned 403 "The uploaded file is invalid". Someone whose file was fine was told it was not, and the file was gone. A detection now keeps its 403 and its delete; a scan that failed returns 500 with the daemon's own reply and leaves the upload alone. This is live on main: `Tests / E2E / Antivirus` fails 2 runs in 19 with `INSTREAM: Size limit reached, (requested: 247036)` -- a length read out of file bytes -- surfacing as `403 matches expected 201`. Verified against clamd 1.4 with a custom signature rather than EICAR, and StreamMaxLength lowered to force a refusal: clean file clean - detected (custom signature) infected Appwrite.Test.Marker.UNOFFICIAL oversized failed - No E2E covers the failed-scan branch. Reaching a reply-level refusal needs StreamMaxLength below APP_LIMIT_ANTIVIRUS, and they default to 25M and 20M, so the only way to trigger it in that lane would be to reconfigure the shared daemon and stop it testing the configuration we ship. The classification itself is covered in php-clamav, where the tests fail on the previous semantics with the size refusal reporting 'infected' where 'failed' is expected. Co-Authored-By: Claude Opus 5 <[email protected]>
Contributor
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
ChiragAgg5k
approved these changes
Sep 10, 2026
2 of 4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tests / E2E / Antivirusfails 2 runs in 19 onmainwithand, in the container log,
INSTREAM: Size limit reached, (requested: 247036)— a length read out of file bytes rather than a real size.Why
appwrite/php-clamav2.0.0 sizes every INSTREAM frame at the fixed chunk length rather than the bytes actually read, and loops on!feof(), which only becomes true after a read has hit the end. The trailing read returns''andpack('Na8192', 8192, '')still declares a full chunk:The framing then desyncs, ClamAV reads file content as a 4-byte length prefix, and answers with an error instead of a verdict. 2.0.1 fixed the framing; 2.0.2 added a result type. Both are taken here.
The half that matters even once the framing is right
fileScanInStream()returned a bare bool, so a scan that could not happen answered exactly like a detection:stream: OKtruestream: Test.Sig FOUNDfalseINSTREAM size limit exceeded. ERRORfalseCreate.phpread thatfalse, deleted the uploaded file and returned403 STORAGE_INVALID_FILE— "The uploaded file is invalid". Someone whose file was fine was told it was not, and the file was gone.Now a detection keeps its 403 and its delete, and a scan that failed returns 500 with the daemon's own reply and leaves the upload alone.
Establishing the trigger
Two plausible triggers were checked and are not it, so they are not worth re-investigating:
clamdscan --reload: 120true, zero failures, zero throws.clamav/clamav:1.4-debian,ping()and a clean scan go green at the same moment (14.8 s).What produces it is any reply that is neither
OKnor... FOUND.Verified
Against clamd 1.4, using a custom signature rather than EICAR (developer machines delete EICAR files), with
StreamMaxLengthlowered to force a refusal:Not verified
No E2E covers the failed-scan branch. Reaching a reply-level refusal needs
StreamMaxLengthbelowAPP_LIMIT_ANTIVIRUS, and they default to 25M and 20M — so the only way to trigger it in the Antivirus lane would be to lower the shared daemon's limit, which would stop that lane testing the configuration we ship. The classification itself is covered upstream in php-clamav, where the tests fail on the previous semantics with the size refusal reportinginfectedwherefailedis expected.Note also that with stock configuration the size-limit path is not reachable — 20M sits under the 25M default. What made it reachable was the doubling, which is fixed here. It returns if anyone lowers
StreamMaxLengthbelow 20M or raisesAPP_LIMIT_ANTIVIRUS.🤖 Generated with Claude Code