[PR #254] [CLOSED] Fix off-by-one error on NewRangeReader #461

Closed
opened 2026-03-03 12:30:08 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/fsouza/fake-gcs-server/pull/254
Author: @chowey
Created: 5/28/2020
Status: Closed

Base: masterHead: rangereader


📝 Commits (2)

  • 2c21831 Add test for failing NewRangeReader
  • 723d3ca Fix range requests to account for difference between RFC and how go works

📊 Changes

2 files changed (+52 additions, -2 deletions)

View changed files

📝 fakestorage/object.go (+4 -2)
📝 fakestorage/object_test.go (+48 -0)

📄 Description

For Range request headers, per RFC 7233:

byte-range = first-byte-pos "-" last-byte-pos

In other words, the byte-range uses the last-byte-pos. This is subtly different than how Go slice indexing works per the Go language spec:

The indices low and high select which elements of operand a appear in the result. The result has indices starting at 0 and length equal to high - low.

Therefore, we should take the last-byte-pos from the Range header and increment it by one to get the high that is expected by Go.

I created a test that illustrates the point.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/fsouza/fake-gcs-server/pull/254 **Author:** [@chowey](https://github.com/chowey) **Created:** 5/28/2020 **Status:** ❌ Closed **Base:** `master` ← **Head:** `rangereader` --- ### 📝 Commits (2) - [`2c21831`](https://github.com/fsouza/fake-gcs-server/commit/2c21831a200dc841565e90e46e5f6cb6b0fac2d7) Add test for failing NewRangeReader - [`723d3ca`](https://github.com/fsouza/fake-gcs-server/commit/723d3ca0b397c94373d0f99613558416fc412054) Fix range requests to account for difference between RFC and how go works ### 📊 Changes **2 files changed** (+52 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `fakestorage/object.go` (+4 -2) 📝 `fakestorage/object_test.go` (+48 -0) </details> ### 📄 Description For Range request headers, per [RFC 7233](https://tools.ietf.org/html/rfc7233#section-4.2): > `byte-range = first-byte-pos "-" last-byte-pos` In other words, the `byte-range` uses the `last-byte-pos`. This is subtly different than how Go slice indexing works [per the Go language spec](https://golang.org/ref/spec#Slice_expressions): > The *indices* `low` and `high` select which elements of operand `a` appear in the result. The result has indices starting at 0 and length equal to `high - low`. Therefore, we should take the `last-byte-pos` from the Range header and increment it by one to get the `high` that is expected by Go. I created a test that illustrates the point. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-03 12:30:08 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/fake-gcs-server#461
No description provided.