From d1f5ce24355f7fc124790e8cf7a2a7d24efa4cee Mon Sep 17 00:00:00 2001 From: Gwenael Treguier Date: Sat, 8 Aug 2015 09:39:35 +0200 Subject: [PATCH] Check when buffer is too long. --- src/blob.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/blob.rs b/src/blob.rs index 747c729..0d9691a 100644 --- a/src/blob.rs +++ b/src/blob.rs @@ -45,6 +45,12 @@ impl<'conn> SqliteBlob<'conn> { } pub fn read(&mut self, buf: &mut [u8]) -> SqliteResult { + 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 size = self.size(); if self.pos + n > size { @@ -61,6 +67,12 @@ impl<'conn> SqliteBlob<'conn> { } pub fn write(&mut self, buf: &[u8]) -> SqliteResult { + 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 size = self.size(); if self.pos + n > size {