Skip to content

Conversation

@platypii
Copy link
Contributor

In a range request, the rangeEnd is meant to be inclusive, but undici has a bug in its handling of range requests on blob uri's that misses the last character.

This relates to...

Fix for nodejs/node#60382

Credit to @severo for discovering this bug.

Rationale

The fetch spec clearly states that:

Let slicedBlob be the result of invoking slice blob given blob, rangeStart, rangeEnd + 1, and type.

Note: A range header denotes an inclusive byte range, while the slice blob algorithm input range does not. To use the slice blob algorithm, we have to increment rangeEnd.

And funny enough, in the undici code the COMMENT is correct but the code is off by one:

        // 8. Let slicedBlob be the result of invoking slice blob given blob, rangeStart,
        //    rangeEnd + 1, and type.
        const slicedBlob = blob.slice(rangeStart, rangeEnd, type)

Changes

Fixes the off-by-one error in range requests by adding 1 to the rangeEnd slice.

        // 8. Let slicedBlob be the result of invoking slice blob given blob, rangeStart,
        //    rangeEnd + 1, and type.
        const slicedBlob = blob.slice(rangeStart, rangeEnd + 1, type)

Includes a test which fails on master but passes with this fix.

Features

n/a

Bug Fixes

Fixes nodejs/node#60382

Breaking Changes and Deprecations

n/a

Status

@Uzlopak Uzlopak requested a review from Copilot October 26, 2025 08:28
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an off-by-one error in the handling of range requests for blob URIs. The rangeEnd parameter in HTTP range requests is inclusive, but the slice operation was not adding 1 as required by the fetch specification, causing the last byte to be omitted.

Key Changes:

  • Fixed the blob slice operation to correctly add 1 to rangeEnd to include the final byte
  • Added a test case to verify that range requests return the correct inclusive byte range

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
lib/web/fetch/index.js Corrected the blob.slice call to add 1 to rangeEnd, aligning implementation with the fetch specification
test/fetch/blob-uri.js Added test verifying that range requests properly return inclusive byte ranges

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.85%. Comparing base (b958ea0) to head (ef698e0).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4643   +/-   ##
=======================================
  Coverage   92.85%   92.85%           
=======================================
  Files         106      106           
  Lines       33111    33111           
=======================================
  Hits        30745    30745           
  Misses       2366     2366           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina requested a review from KhafraDev October 26, 2025 09:06
Copy link
Contributor

@Uzlopak Uzlopak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@KhafraDev KhafraDev merged commit 0c61d52 into nodejs:main Oct 26, 2025
32 of 35 checks passed
@github-actions github-actions bot mentioned this pull request Jan 5, 2026
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.

Range request on Object URL does not include the "end" byte

8 participants