(root: &Path, target: &Path)
| 87 | read_zip_file_entry_with_limits(path, name, ZipLimits::default()) |
| 88 | } |
| 89 | |
| 90 | pub fn read_zip_file_entry_with_limits( |
| 91 | path: impl AsRef<Path>, |
| 92 | name: &str, |
| 93 | limits: ZipLimits, |
| 94 | ) -> io::Result<Vec<u8>> { |
| 95 | let file = fs::File::open(path)?; |
| 96 | let mut archive = zip::ZipArchive::new(file).map_err(zip_error_to_io)?; |
| 97 | check_entry_count(archive.len(), limits)?; |
| 98 | let mut entry = archive.by_name(name).map_err(zip_error_to_io)?; |
| 99 | check_entry_metadata(&entry, limits)?; |
| 100 | let byte_limit = limits.max_entry_bytes.min(limits.max_total_bytes); |
| 101 | let capacity = usize::try_from(entry.size().min(byte_limit)).unwrap_or(usize::MAX); |
| 102 | let mut out = Vec::new(); |
| 103 | out.try_reserve(capacity) |
| 104 | .map_err(|err| io::Error::other(format!("zip entry allocation failed: {err}")))?; |
no test coverage detected