-
-
Notifications
You must be signed in to change notification settings - Fork 689
fix: fetch blob with range off-by-one error #4643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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
rangeEndto 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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
mcollina
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Uzlopak
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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:
And funny enough, in the undici code the COMMENT is correct but the code is off by one:
Changes
Fixes the off-by-one error in range requests by adding 1 to the rangeEnd slice.
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