Skip to content

Commit a6c9776

Browse files
fix: handle Suffix(0) as unsatisfiable instead of panicking
`Range: bytes=-0` would pass the `checked_sub` guard (since `size - 0 = size`), then compute `start = size, end = size - 1`, causing `Bound::new` to fail and the `unwrap()` to panic. Validate that the computed start position is within bounds by using `is_some_and(|start| start < size)`.
1 parent f4d07d4 commit a6c9776

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub fn file_range(
7878
range: start..=end,
7979
})
8080
}
81-
HttpRange::Suffix(suffix) if size.checked_sub(suffix).is_some() => {
81+
HttpRange::Suffix(suffix) if size.checked_sub(suffix).is_some_and(|start| start < size) => {
8282
let start = size - suffix;
8383
let end = size - 1;
8484
let content_range =

0 commit comments

Comments
 (0)