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

Function decompress

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

Streaming zstd decompress with a hard output ceiling. Reads at most `max_len + 1` bytes so an overrun is detected without buffering the whole bomb.

(bytes: &[u8], max_len: usize)

Source from the content-addressed store, hash-verified

328/// `max_len + 1` bytes so an overrun is detected without buffering the whole
329/// bomb.
330fn decompress(bytes: &[u8], max_len: usize) -> Result<Vec<u8>, SyncError> {
331 let decoder = zstd::stream::read::Decoder::new(bytes).map_err(SyncError::Compression)?;
332 let mut out = Vec::new();
333 let read = decoder
334 .take(max_len as u64 + 1)
335 .read_to_end(&mut out)
336 .map_err(SyncError::Compression)?;
337 if read > max_len {
338 return Err(SyncError::TooLarge { limit: max_len });
339 }
340 Ok(out)
341}
342
343#[cfg(test)]
344mod tests {

Callers 1

decode_with_limitFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected