Skip to content

Commit 28fcf33

Browse files
authored
fix: Avoid panics when content is longer than content length header (#33)
1 parent 914f690 commit 28fcf33

File tree

2 files changed

+317
-20
lines changed

2 files changed

+317
-20
lines changed

src/error.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,31 @@ pub enum AsyncHttpRangeReaderError {
3232
MemoryMapError(#[source] Arc<std::io::Error>),
3333

3434
/// Error from `http-content-range`
35-
#[error("Invalid Content-Range header: {0}")]
35+
#[error("invalid Content-Range header: {0}")]
3636
ContentRangeParser(String),
37+
38+
/// The server returned an invalid range response
39+
#[error(
40+
"request and response range mismatch, \
41+
expected {expected_start}-{expected_end_inclusive}/{expected_complete_length}, \
42+
got {actual_start}-{actual_end_inclusive}/{actual_complete_length}"
43+
)]
44+
RangeMismatch {
45+
expected_start: u64,
46+
expected_end_inclusive: u64,
47+
expected_complete_length: usize,
48+
actual_start: u64,
49+
actual_end_inclusive: u64,
50+
actual_complete_length: u64,
51+
},
52+
53+
/// The server returned more bytes than the range request asked for
54+
#[error("range response returned more than the expected {expected} bytes")]
55+
ResponseTooLong { expected: u64 },
56+
57+
/// The server returned fewer bytes than the range request asked for
58+
#[error("expected {expected} bytes from range response, got {actual}")]
59+
ResponseTooShort { expected: u64, actual: u64 },
3760
}
3861

3962
impl From<std::io::Error> for AsyncHttpRangeReaderError {

0 commit comments

Comments
 (0)