fix: handle virtual filesystem files reporting 0 size (e.g., /proc/*)#314
Closed
hanu-14 wants to merge 1 commit into
Closed
fix: handle virtual filesystem files reporting 0 size (e.g., /proc/*)#314hanu-14 wants to merge 1 commit into
hanu-14 wants to merge 1 commit into
Conversation
res.download() and res.sendFile() failed for Linux /proc/* files because fs.stat() reports size === 0 for virtual filesystem files, causing the send module to either return a 416 Range Not Satisfiable or serve an empty response with Content-Length: 0. The fix detects regular files with stat.size === 0 as potentially virtual (procfs, sysfs) and: 1. Skips range parsing (unknown size cannot satisfy range requests) 2. Omits Content-Length header (uses Transfer-Encoding: chunked) 3. Omits stream opts.end (reads to natural end of file) Fixes expressjs/express#4944
|
There are 3 other PRs targetting the same issue:
This PR seems to be functionally identical to #311, so I'm closing it as a duplicate. |
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.
Description
Fixes expressjs/express#4944 -
res.download()andres.sendFile()fail for Linux/proc/*files becausefs.stat()reportssize === 0for virtual filesystem files.Root Cause
The
sendmodule usesstat.sizeto determine file length. For virtual filesystems like/proc,stat()returnssize: 0even though the file contains data when read. This causes:parseRange(0, ranges)rejects all ranges, returning a 416 Range Not Satisfiable errorContent-Length: 0is set, serving an empty response despite contentFix
Added an
isVirtualcheck: when a regular file (stat.isFile()) reportssize === 0, treat it as potentially virtual (procfs, sysfs). For these files:Content-Lengthheader is omitted (uses chunked transfer)opts.endis omitted (reads to natural end)All 139 existing tests pass.