fix: accept files exactly at fileSize limit#1382
Open
abhu85 wants to merge 1 commit intoexpressjs:mainfrom
Open
fix: accept files exactly at fileSize limit#1382abhu85 wants to merge 1 commit intoexpressjs:mainfrom
abhu85 wants to merge 1 commit intoexpressjs:mainfrom
Conversation
Busboy emits the 'limit' event when fileSize equals limits.fileSize, causing multer to reject files that are exactly at the limit. Files at the limit should be accepted; only files exceeding the limit should be rejected. The fix passes fileSize + 1 to busboy so that files at the exact limit don't trigger the limit event. Files 1 byte over the limit will still trigger the event correctly. Added tests verifying: - File exactly at limit is accepted - File 1 byte over limit is rejected - Empty file accepted when limit is 0 - Non-empty file rejected when limit is 0 Fixes expressjs#1348
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.
Summary
Fixes #1348
Busboy emits the
'limit'event whenfileSizeequalslimits.fileSize, causing multer to reject files that are exactly at the configured limit. This is an off-by-one error - files at the limit should be accepted; only files exceeding the limit should be rejected.Root Cause
In busboy's multipart.js:
The
'limit'event fires when the file size equals the limit, not when it exceeds it. This is arguably correct behavior for busboy (it can't know if more bytes are coming), but multer should handle this case gracefully.Solution
Pass
fileSize + 1to busboy so that files at the exact limit don't trigger the limit event. Files 1 byte over the configured limit will still trigger the event correctly.Test Plan