Limit deserialization of data coming off the wire (#6751)

* Limit deserialization of data coming off the wire

* Feedback and cleanup
This commit is contained in:
Jack May
2019-11-06 00:07:57 -08:00
committed by GitHub
parent 8e3be6413e
commit 9614d17024
9 changed files with 49 additions and 28 deletions

View File

@@ -85,6 +85,15 @@ pub fn to_packets<T: Serialize>(xs: &[T]) -> Vec<Packets> {
to_packets_chunked(xs, NUM_PACKETS)
}
pub fn limited_deserialize<T>(data: &[u8]) -> bincode::Result<T>
where
T: serde::de::DeserializeOwned,
{
bincode::config()
.limit(PACKET_DATA_SIZE as u64)
.deserialize(data)
}
#[cfg(test)]
mod tests {
use super::*;