Decompress and deserialize a wire body, refusing to inflate past `max_len` bytes. The bound is enforced during decompression (streaming), so a zip bomb is stopped before it is fully materialized.
(
bytes: &[u8],
max_len: usize,
)
| 311 | /// bytes. The bound is enforced during decompression (streaming), so a zip bomb |
| 312 | /// is stopped before it is fully materialized. |
| 313 | pub fn decode_with_limit<T: DeserializeOwned>( |
| 314 | bytes: &[u8], |
| 315 | max_len: usize, |
| 316 | ) -> Result<T, SyncError> { |
| 317 | let raw = decompress(bytes, max_len)?; |
| 318 | postcard::from_bytes(&raw).map_err(SyncError::Codec) |
| 319 | } |
| 320 | |
| 321 | /// Streaming zstd decompress with a hard output ceiling. Reads at most |
| 322 | /// `max_len + 1` bytes so an overrun is detected without buffering the whole |