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

Function decode_with_limit

atomic-objects/src/sync.rs:313–319  ·  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

311/// bytes. The bound is enforced during decompression (streaming), so a zip bomb
312/// is stopped before it is fully materialized.
313pub 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

Callers 1

decodeFunction · 0.85

Calls 1

decompressFunction · 0.85

Tested by

no test coverage detected