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

Function decompress

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

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

Callers 1

decode_with_limitFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected