mirror of
https://github.com/librespot-org/librespot.git
synced 2024-11-08 16:45:43 +00:00
Improve range checks
This commit is contained in:
parent
e627cb4b35
commit
0cc4466245
2 changed files with 11 additions and 4 deletions
|
@ -558,7 +558,7 @@ impl Read for AudioFileStreaming {
|
||||||
let available_length = download_status
|
let available_length = download_status
|
||||||
.downloaded
|
.downloaded
|
||||||
.contained_length_from_value(offset);
|
.contained_length_from_value(offset);
|
||||||
assert!(available_length > 0);
|
|
||||||
drop(download_status);
|
drop(download_status);
|
||||||
|
|
||||||
self.position = self.read_file.seek(SeekFrom::Start(offset as u64))?;
|
self.position = self.read_file.seek(SeekFrom::Start(offset as u64))?;
|
||||||
|
|
|
@ -53,8 +53,7 @@ async fn receive_data(
|
||||||
Some(Err(e)) => break Err(e.into()),
|
Some(Err(e)) => break Err(e.into()),
|
||||||
None => {
|
None => {
|
||||||
if actual_length != request.length {
|
if actual_length != request.length {
|
||||||
let msg =
|
let msg = format!("did not expect body to contain {} bytes", actual_length);
|
||||||
format!("did not expect body to contain {} bytes", actual_length,);
|
|
||||||
break Err(Error::data_loss(msg));
|
break Err(Error::data_loss(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,6 +82,11 @@ async fn receive_data(
|
||||||
if measure_ping_time {
|
if measure_ping_time {
|
||||||
let mut duration = Instant::now() - request.request_time;
|
let mut duration = Instant::now() - request.request_time;
|
||||||
if duration > MAXIMUM_ASSUMED_PING_TIME {
|
if duration > MAXIMUM_ASSUMED_PING_TIME {
|
||||||
|
warn!(
|
||||||
|
"Ping time {} ms exceeds maximum {}, setting to maximum",
|
||||||
|
duration.as_millis(),
|
||||||
|
MAXIMUM_ASSUMED_PING_TIME.as_millis()
|
||||||
|
);
|
||||||
duration = MAXIMUM_ASSUMED_PING_TIME;
|
duration = MAXIMUM_ASSUMED_PING_TIME;
|
||||||
}
|
}
|
||||||
file_data_tx.send(ReceivedData::ResponseTime(duration))?;
|
file_data_tx.send(ReceivedData::ResponseTime(duration))?;
|
||||||
|
@ -135,7 +139,10 @@ impl AudioFileFetch {
|
||||||
}
|
}
|
||||||
|
|
||||||
if offset + length > self.shared.file_size {
|
if offset + length > self.shared.file_size {
|
||||||
length = self.shared.file_size - offset;
|
return Err(Error::out_of_range(format!(
|
||||||
|
"Range {} +{} exceeds file size {}",
|
||||||
|
offset, length, self.shared.file_size
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut ranges_to_request = RangeSet::new();
|
let mut ranges_to_request = RangeSet::new();
|
||||||
|
|
Loading…
Reference in a new issue