protect against corruption (#4741)

This commit is contained in:
Rob Walker 2019-06-19 21:29:36 -07:00 committed by GitHub
parent c228792967
commit 3600a926df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 0 deletions

View File

@ -65,6 +65,9 @@ impl Account {
}
pub fn serialize_data<T: serde::Serialize>(&mut self, state: &T) -> Result<(), bincode::Error> {
if bincode::serialized_size(state)? > self.data.len() as u64 {
return Err(Box::new(bincode::ErrorKind::SizeLimit));
}
bincode::serialize_into(&mut self.data[..], state)
}
}