Skip to content

Commit d2cadec

Browse files
Merge pull request plietar#262 from librespot-org/seek-eof
Fix seek past EOF panic for some tracks
2 parents 96557b4 + 74e0ada commit d2cadec

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

audio/src/fetch.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,16 @@ impl Read for AudioFileStreaming {
348348
impl Seek for AudioFileStreaming {
349349
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
350350
self.position = try!(self.read_file.seek(pos));
351+
// Do not seek past EOF
352+
if (self.position as usize % CHUNK_SIZE) != 0 {
353+
// Notify the fetch thread to get the correct block
354+
// This can fail if fetch thread has completed, in which case the
355+
// block is ready. Just ignore the error.
356+
let _ = self.seek.unbounded_send(self.position);
357+
} else {
358+
warn!("Trying to seek past EOF");
359+
}
351360

352-
// Notify the fetch thread to get the correct block
353-
// This can fail if fetch thread has completed, in which case the
354-
// block is ready. Just ignore the error.
355-
let _ = self.seek.unbounded_send(self.position);
356361
Ok(self.position)
357362
}
358363
}

0 commit comments

Comments
 (0)