mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Prevent seek before offset
This commit is contained in:
parent
8d8d6d4fd8
commit
78216eb6ee
1 changed files with 11 additions and 10 deletions
|
@ -2195,19 +2195,20 @@ impl<T: Read + Seek> Seek for Subfile<T> {
|
||||||
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
|
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
|
||||||
let pos = match pos {
|
let pos = match pos {
|
||||||
SeekFrom::Start(offset) => SeekFrom::Start(offset + self.offset),
|
SeekFrom::Start(offset) => SeekFrom::Start(offset + self.offset),
|
||||||
x => x,
|
SeekFrom::End(offset) => {
|
||||||
|
if (self.length as i64 - offset) < self.offset as i64 {
|
||||||
|
return Err(io::Error::new(
|
||||||
|
io::ErrorKind::InvalidInput,
|
||||||
|
"newpos would be < self.offset",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
pos
|
||||||
|
}
|
||||||
|
_ => pos,
|
||||||
};
|
};
|
||||||
|
|
||||||
let newpos = self.stream.seek(pos)?;
|
let newpos = self.stream.seek(pos)?;
|
||||||
|
|
||||||
if newpos >= self.offset {
|
|
||||||
Ok(newpos - self.offset)
|
Ok(newpos - self.offset)
|
||||||
} else {
|
|
||||||
Err(io::Error::new(
|
|
||||||
io::ErrorKind::UnexpectedEof,
|
|
||||||
"newpos < self.offset",
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue