Check when buffer is too long.

This commit is contained in:
Gwenael Treguier 2015-08-08 09:39:35 +02:00
parent 1bf12f8150
commit d1f5ce2435

View File

@ -45,6 +45,12 @@ impl<'conn> SqliteBlob<'conn> {
} }
pub fn read(&mut self, buf: &mut [u8]) -> SqliteResult<i32> { pub fn read(&mut self, buf: &mut [u8]) -> SqliteResult<i32> {
if buf.len() > ::std::i32::MAX as usize {
return Err(SqliteError {
code: ffi::SQLITE_TOOBIG,
message: "buffer too long".to_string()
});
}
let mut n = buf.len() as i32; let mut n = buf.len() as i32;
let size = self.size(); let size = self.size();
if self.pos + n > size { if self.pos + n > size {
@ -61,6 +67,12 @@ impl<'conn> SqliteBlob<'conn> {
} }
pub fn write(&mut self, buf: &[u8]) -> SqliteResult<i32> { pub fn write(&mut self, buf: &[u8]) -> SqliteResult<i32> {
if buf.len() > ::std::i32::MAX as usize {
return Err(SqliteError {
code: ffi::SQLITE_TOOBIG,
message: "buffer too long".to_string()
});
}
let n = buf.len() as i32; let n = buf.len() as i32;
let size = self.size(); let size = self.size();
if self.pos + n > size { if self.pos + n > size {