mirror of
https://github.com/isar/rusqlite.git
synced 2025-04-20 08:17:44 +08:00
Fix logic in seek to disallow seeking past the end
This commit is contained in:
parent
af9b45851a
commit
900c241c4e
@ -161,9 +161,9 @@ impl<'conn> io::Seek for Blob<'conn> {
|
|||||||
if pos < 0 {
|
if pos < 0 {
|
||||||
Err(io::Error::new(io::ErrorKind::InvalidInput,
|
Err(io::Error::new(io::ErrorKind::InvalidInput,
|
||||||
"invalid seek to negative position"))
|
"invalid seek to negative position"))
|
||||||
} else if pos > ::std::i32::MAX as i64 {
|
} else if pos > self.size() as i64 {
|
||||||
Err(io::Error::new(io::ErrorKind::InvalidInput,
|
Err(io::Error::new(io::ErrorKind::InvalidInput,
|
||||||
"invalid seek to position > i32::MAX"))
|
"invalid seek to position past end of blob"))
|
||||||
} else {
|
} else {
|
||||||
self.pos = pos as i32;
|
self.pos = pos as i32;
|
||||||
Ok(pos as u64)
|
Ok(pos as u64)
|
||||||
@ -231,6 +231,11 @@ mod test {
|
|||||||
blob.reopen(rowid).unwrap();
|
blob.reopen(rowid).unwrap();
|
||||||
assert_eq!(5, blob.read(&mut bytes[..]).unwrap());
|
assert_eq!(5, blob.read(&mut bytes[..]).unwrap());
|
||||||
assert_eq!(&bytes, b"Clob5");
|
assert_eq!(&bytes, b"Clob5");
|
||||||
|
|
||||||
|
// should not be able to seek negative or past end
|
||||||
|
assert!(blob.seek(SeekFrom::Current(-20)).is_err());
|
||||||
|
assert!(blob.seek(SeekFrom::End(0)).is_ok());
|
||||||
|
assert!(blob.seek(SeekFrom::Current(1)).is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user