Skip to content

cli: avoid using Content-Length as total size on bounded 206 and 416 responses - #433

Open
Pybsama wants to merge 1 commit into
Nehanth:mainfrom
Pybsama:fix/pull-total-size-range-headers
Open

Pybsama wants to merge 1 commit into
Nehanth:mainfrom
Pybsama:fix/pull-total-size-range-headers

Conversation

@Pybsama

@Pybsama Pybsama commented Dec 2, 2026

Copy link
Copy Markdown

What

In cli/lib/cache.js, totalOf(res, from) fell back to Content-Length whenever Content-Range lacked a numeric /total suffix, and both pullSegmented() (bounded Range: bytes=a-b 206 responses) and the 416 resume check in pullFile() passed from = 0:

  • On bounded 206 segment responses where Content-Range is bytes a-b/* or omitted, totalOf(res, 0) treated the single segment's Content-Length as the full file size and aborted the download with a false size mismatch.
  • On 416 responses without a Content-Range header, totalOf(res, 0) treated the error body's Content-Length as the total file size instead of falling back to f.bytes, discarding an already-complete .part file and re-downloading it from scratch.
  • Non-numeric Content-Length values could also coerce to NaN.

This change restricts the Content-Length fallback in totalOf() to 200 responses and open-ended 206 responses (from != null) with a strict digit check, passes from = null for bounded 206 segments and 416 responses, and adds HTTP server regression tests in cli/test/pull_test.mjs.

Correctness

  • CLI download/range unit tests pass (no engine, kernel, or Code mode files changed).

Tested on

  • Node.js v24.18.1 on macOS (arm64):
    • node --test cli/test/pull_test.mjs — 13 passed, 0 failed
    • npm run test:packages — 213 passed, 6 skipped, 0 failed
    • npm run test:runtime — 6/6 checks passed (172 frames)
    • CI node --check syntax sweep across JS/MJS modules — all passed

…nses

In cli/lib/cache.js, totalOf(res, 0) fell back to Content-Length when
Content-Range lacked a numeric '/total'. For segmented downloads
(bounded 206 ranges with 'Content-Range: bytes a-b/*' or omitted
Content-Range), that treated a single segment's length as the whole
file size and aborted the download with a false size mismatch. For
416 responses without Content-Range, it treated the error body's
Content-Length as the file size instead of falling back to f.bytes,
causing already-complete .part files to be discarded and re-downloaded.
@Pybsama
Pybsama requested a review from Nehanth as a code owner December 2, 2026 20:16
@vercel

vercel Bot commented Dec 2, 2026

Copy link
Copy Markdown

@Pybsama is attempting to deploy a commit to the nehanth's projects Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant