Default `ObjectStore::get_ranges` panics when a range past the end of the object is coalesced with an earlier range
Maintainers usually reply within 2 days
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 70/100
Research direction
Read coalesce_ranges in src/util.rs: after a merged fetch, each requested range is sliced out of the buffer with the end clamped but the start unchecked. Start by reproducing with a coalesce_ranges unit test using a fake fetch closure, then make a range whose start is past the returned bytes fall back to its own fetch and return that error. Also add a get_ranges assertion to put_get_delete_list in src/integration.rs so the store integrations cover it. Note the reporter says a fix and tests already exist, so check for a PR before starting.
Written by the indexing model from the issue text.
Description
Describe the bug
The default ObjectStore::get_ranges implementation (coalesce_ranges) panics with range start must not be greater than end when one of the requested ranges starts after the end of the object and is merged with an earlier, in-bounds range. If the range starts exactly at the end of the object, it returns an empty Bytes instead of an error.
Requesting the same range on its own with get_range returns an error. So does get_ranges on InMemory and LocalFileSystem, which have their own implementations. AmazonS3, GoogleCloudStorage, MicrosoftAzure and HttpStore use the default implementation, so they take this path. For example, a reader working from a truncated file or bad metadata can ask for such ranges, and the caller then gets a panic instead of an error it can handle.
To Reproduce
With object_store from main and tokio (features macros, rt-multi-thread):
use object_store::memory::InMemory;
use object_store::path::Path;
use object_store::{OBJECT_STORE_COALESCE_DEFAULT, ObjectStoreExt, coalesce_ranges};
#[tokio::main]
async fn main() {
let store = InMemory::new();
let path = Path::from("obj");
store.put(&path, "arbitrary data".into()).await.unwrap(); // 14 bytes
// A range starting past the end of the object is an error when requested on its own
let r = store.get_range(&path, 200..300).await;
println!("get_range(200..300) -> {:?}", r.map_err(|e| e.to_string()));
// Body of the default `ObjectStore::get_ranges`
for ranges in [vec![0..5, 14..20], vec![0..5, 200..300]] {
let r = coalesce_ranges(
&ranges,
|r| store.get_range(&path, r),
OBJECT_STORE_COALESCE_DEFAULT,
)
.await;
println!("get_ranges({ranges:?}) -> {:?}", r.map_err(|e| e.to_string()));
}
}
Output:
get_range(200..300) -> Err("Generic InMemory error: Invalid range: Wanted range starting at 200, but object was only 14 bytes long")
get_ranges([0..5, 14..20]) -> Ok([b"arbit", b""])
thread 'main' panicked at .../bytes-1.12.1/src/bytes.rs:374:28:
range start must not be greater than end: 200 <= 14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
The loop body is the same as the default get_ranges. I also checked a real store: HttpStore against a small server that follows RFC 9110. That server answers bytes=0-299 on the 14-byte object with 206 and Content-Range: bytes 0-13/14, and answers bytes=200-299 with 416. Against it, get_range(200..300) returns the 416 error, get_ranges(&[0..5, 200..300]) panics with the same message, and get_ranges(&[0..5, 14..20]) returns [b"arbit", b""]. Calling InMemory::get_ranges or LocalFileSystem::get_ranges with the same ranges returns an error. In-bounds ranges such as [0..5, 7..9] work on all of them.
The cause is in coalesce_ranges in src/util.rs:
0..5and200..300are merged into a single fetch of0..300.- A bounded range that runs past the end of the object is truncated. This is the documented
GetRange::Boundedbehaviour, and the HTTP client accepts thebytes 0-13/14response for it. So the merged fetch returns 14 bytes. - Each requested range is then sliced out of that buffer. The end of the slice is clamped to the buffer length, but the start is not checked.
slice(200..14)panics, andslice(14..14)returns an empty buffer.
Expected behavior
get_ranges should return an error for a range that starts at or after the end of the object. That matches get_range for the same range, and InMemory/LocalFileSystem::get_ranges. RFC 9110 section 14.1.2 treats such a range (first position at or past the representation length) as unsatisfiable. The GetRange::Bounded docs say "If the given range is zero-length or starts after the end of the object, an error will be returned". put_get_delete_list in src/integration.rs already expects get_range(200..300) to be a non-fatal error.
Proposed fix: in coalesce_ranges, when the bytes returned for a merged fetch end before a requested range starts, fetch that range on its own and return what the store returns, which is normally its out-of-range error. The public signature stays the same, and the extra request only happens in this error case. Ranges that start inside the object but run past its end are still truncated as today.
Additional context
- object_store main at c216ede (version 0.14.2)
- macOS 26.6 arm64, rustc 1.100.0
- The end clamp was added in apache/arrow-rs#5222. That change made bounded ranges past the end get truncated instead of rejected, but the start of each slice was never checked.
- I have a fix with a regression test: a unit test for
coalesce_ranges, plus aget_rangesassertion input_get_delete_listso the S3/GCS/Azure/HTTP integration runs cover it. I'm happy to open a PR.
This issue was drafted with Claude Code (claude-opus-5-5); the results above are from the runs described.
- Dominant language
- Rust
- Stars
- 339
- Forks
- 240
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 3
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/arrow-rs-object-store
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
apache/arrow-rs-object-store#914 ·
Maintainers usually reply within 2 days
-
`hyper::Error::is_incomplete_message()` classified as `HttpErrorKind::Request`, retrying non idempotent `PutMode::Create`Possibly taken @hcrosse claimed this 3 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
apache/arrow-rs-object-store#912 ·
Maintainers usually reply within 2 days
-
AWS: list requests are signed without ClientOptions default headers (sent unsigned, S3 403 HeadersNotSigned)Possibly taken @filippoGRiva claimed this 8 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
apache/arrow-rs-object-store#877 ·
Maintainers usually reply within 2 days
-
List requests do not map HTTP status codes to error variants, so 403 and 404 both become `Error::Generic`May be free again A pull request for this issue was closed without being merged. Open
Difficulty 2/5 Half a day Newbie friendliness 82/100
apache/arrow-rs-object-store#851 · 2 comments · 1 reaction ·
Maintainers usually reply within 2 days
-
Errors on 200 Response for entire-object range requestMay be free again A pull request for this issue was closed without being merged. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
apache/arrow-rs-object-store#806 · 2 comments ·
Maintainers usually reply within 2 days
All issues in apache/arrow-rs-object-store
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
kashsuks/Pinel#172 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 69/100
Maintainers usually reply within 1 day
-
test_a_503_raises_unavailable_error fails on macOS about one run in sixPossibly taken @naman-modi claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
bug ui
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
userFRM/egui-charts#4168 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Maintainers usually reply within 1 day