Skip to content

fix: handle virtual filesystem files reporting 0 size (e.g., /proc/*)#314

Closed
hanu-14 wants to merge 1 commit into
pillarjs:masterfrom
hanu-14:fix/procfs-zero-size-files
Closed

fix: handle virtual filesystem files reporting 0 size (e.g., /proc/*)#314
hanu-14 wants to merge 1 commit into
pillarjs:masterfrom
hanu-14:fix/procfs-zero-size-files

Conversation

@hanu-14

@hanu-14 hanu-14 commented Jul 22, 2026

Copy link
Copy Markdown

Description

Fixes expressjs/express#4944 - res.download() and res.sendFile() fail for Linux /proc/* files because fs.stat() reports size === 0 for virtual filesystem files.

Root Cause

The send module uses stat.size to determine file length. For virtual filesystems like /proc, stat() returns size: 0 even though the file contains data when read. This causes:

  1. parseRange(0, ranges) rejects all ranges, returning a 416 Range Not Satisfiable error
  2. Content-Length: 0 is set, serving an empty response despite content

Fix

Added an isVirtual check: when a regular file (stat.isFile()) reports size === 0, treat it as potentially virtual (procfs, sysfs). For these files:

  • Range parsing is skipped
  • Content-Length header is omitted (uses chunked transfer)
  • Stream opts.end is omitted (reads to natural end)

All 139 existing tests pass.

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
@krzysdz

krzysdz commented Jul 22, 2026

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

response.download does not return /proc/* files

2 participants