MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / decode_with_limit

Function decode_with_limit

atomic-objects/src/sync.rs:319–325  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

317/// bytes. The bound is enforced during decompression (streaming), so a zip bomb
318/// is stopped before it is fully materialized.
319pub fn decode_with_limit<T: DeserializeOwned>(
320 bytes: &[u8],
321 max_len: usize,
322) -> Result<T, SyncError> {
323 let raw = decompress(bytes, max_len)?;
324 postcard::from_bytes(&raw).map_err(SyncError::Codec)
325}
326
327/// Streaming zstd decompress with a hard output ceiling. Reads at most
328/// `max_len + 1` bytes so an overrun is detected without buffering the whole

Callers 1

decodeFunction · 0.85

Calls 1

decompressFunction · 0.85

Tested by

no test coverage detected