team-ljyzipelo

공개
724줄24 KB
1use crate::{
2 archive::{self, Member, MetadataBudget},
3 crypto,
4 protocol::*,
5 spool,
6};
7use std::{
8 fs::File,
9 io::{Read, Seek, SeekFrom, Write},
10};
11use zeroize::Zeroizing;
12use zlib_rs::{Inflate, InflateFlush, Status, crc32::crc32};
13
14type Result<T> = std::result::Result<T, ErrorCode>;
15const CHUNK: usize = 65536;
16fn at(file: &mut File, offset: u64, bytes: &mut [u8]) -> Result<()> {
17 file.seek(SeekFrom::Start(offset))
18 .map_err(|_| ErrorCode::Io)?;
19 file.read_exact(bytes).map_err(|_| ErrorCode::Integrity)
20}
21fn bytes(file: &mut File, offset: u64, size: usize) -> Result<Vec<u8>> {
22 let mut result = vec![0; size];
23 at(file, offset, &mut result)?;
24 Ok(result)
25}
26fn u16at(b: &[u8], at: usize) -> u16 {
27 u16::from_le_bytes(b[at..at + 2].try_into().unwrap())
28}
29fn u32at(b: &[u8], at: usize) -> u32 {
30 u32::from_le_bytes(b[at..at + 4].try_into().unwrap())
31}
32fn u64at(b: &[u8], at: usize) -> u64 {
33 u64::from_le_bytes(b[at..at + 8].try_into().unwrap())
34}
35fn add(a: u64, b: u64) -> Result<u64> {
36 a.checked_add(b).ok_or(ErrorCode::Integrity)
37}
38fn io<T>(v: std::io::Result<T>) -> Result<T> {
39 v.map_err(crate::space::io_error)
40}
41
42pub(crate) struct Catalog {
43 pub format: Format,
44 pub members: Vec<Member>,
45 pub offsets: Vec<u64>,
46 pub data: File,
47}
48impl Catalog {
49 pub fn open(
50 source: &mut File,
51 len: u64,
52 limits: Limits,
53 decode: bool,
54 password: Option<&[u8]>,
55 check: &mut impl FnMut() -> Result<()>,
56 ) -> Result<Self> {
57 let mut magic = [0; 6];
58 let n = len.min(6) as usize;
59 at(source, 0, &mut magic[..n])?;
60 if magic.starts_with(b"7z\xbc\xaf\x27\x1c") {
61 let bounded = limits.legacy();
62 if len > bounded.input {
63 return Err(ErrorCode::Limit);
64 }
65 let input = bytes(source, 0, len as usize)?;
66 let catalog = archive::parse_with_password(&input, bounded, decode, password, check)?;
67 let mut data = spool::temporary()?;
68 let mut members = catalog.members;
69 let mut offsets = Vec::new();
70 for m in &mut members {
71 offsets.push(io(data.stream_position())?);
72 io(data.write_all(&m.data))?;
73 m.data.clear();
74 m.data.shrink_to_fit();
75 }
76 return Ok(Self {
77 format: Format::SevenZip,
78 members,
79 offsets,
80 data,
81 });
82 }
83 if magic.starts_with(b"PK\x03\x04")
84 || magic.starts_with(b"PK\x05\x06")
85 || magic.starts_with(b"PK\x06\x06")
86 {
87 return zip(source, len, limits, decode, password, check);
88 }
89 if magic.starts_with(&[31, 139]) {
90 let mut data = spool::temporary()?;
91 io(source.rewind())?;
92 let expanded = inflate(source, len, true, limits.output, &mut data, check)?.0;
93 let mut header = [0; 512];
94 if expanded >= 512 {
95 at(&mut data, 0, &mut header)?;
96 if matches!(&header[257..263], b"ustar\0" | b"ustar ") {
97 return tar(data, expanded, limits, Format::TarGzip, check);
98 }
99 }
100 return Ok(Self {
101 format: Format::Gzip,
102 members: vec![Member {
103 entry: Entry {
104 entry_id: 0,
105 name: "GZip stream".to_owned(),
106 kind: EntryKind::File,
107 size: expanded,
108 compressed_size: len,
109 encrypted: false,
110 },
111 data: Vec::new(),
112 }],
113 offsets: vec![0],
114 data,
115 });
116 }
117 if len >= 512 {
118 return tar(io(source.try_clone())?, len, limits, Format::Tar, check);
119 }
120 Err(ErrorCode::UnsupportedFormat)
121 }
122}
123
124fn tar(
125 mut data: File,
126 len: u64,
127 limits: Limits,
128 format: Format,
129 check: &mut impl FnMut() -> Result<()>,
130) -> Result<Catalog> {
131 let mut cursor = 0u64;
132 let mut total = 0u64;
133 let mut members = Vec::new();
134 let mut offsets = Vec::new();
135 let mut metadata = MetadataBudget::default();
136 loop {
137 check()?;
138 let mut header = [0; 512];
139 if add(cursor, 512)? > len {
140 return Err(ErrorCode::Integrity);
141 }
142 at(&mut data, cursor, &mut header)?;
143 if header.iter().all(|b| *b == 0) {
144 if add(cursor, 1024)? > len || len % 512 != 0 {
145 return Err(ErrorCode::Integrity);
146 }
147 let mut buffer = Zeroizing::new([0; CHUNK]);
148 let mut remaining = len - cursor - 512;
149 while remaining != 0 {
150 check()?;
151 let n = remaining.min(CHUNK as u64) as usize;
152 io(data.read_exact(&mut buffer[..n]))?;
153 if buffer[..n].iter().any(|b| *b != 0) {
154 return Err(ErrorCode::Integrity);
155 }
156 remaining -= n as u64;
157 }
158 break;
159 }
160 if members.len() >= limits.entries as usize {
161 return Err(ErrorCode::Limit);
162 }
163 let sum = header
164 .iter()
165 .enumerate()
166 .map(|(i, b)| {
167 if (148..156).contains(&i) {
168 32
169 } else {
170 *b as u64
171 }
172 })
173 .sum::<u64>();
174 if sum != archive::octal(&header[148..156])? {
175 return Err(ErrorCode::Integrity);
176 }
177 let mut name = archive::tar_string(&header[..100])?;
178 if matches!(&header[257..263], b"ustar\0" | b"ustar ") {
179 let prefix = archive::tar_string(&header[345..500])?;
180 if !prefix.is_empty() {
181 name = format!("{prefix}/{name}");
182 }
183 } else if header[257..263].iter().any(|b| *b != 0) {
184 return Err(ErrorCode::UnsupportedFeature);
185 }
186 let kind = match header[156] {
187 0 | b'0' => EntryKind::File,
188 b'5' => EntryKind::Directory,
189 b'1' | b'2' => EntryKind::Link,
190 b'x' | b'g' | b'L' | b'K' => return Err(ErrorCode::UnsupportedFeature),
191 _ => EntryKind::Other,
192 };
193 let size = archive::octal(&header[124..136])?;
194 if kind != EntryKind::File && size != 0 {
195 return Err(ErrorCode::Integrity);
196 }
197 total = total
198 .checked_add(size)
199 .filter(|n| *n <= limits.output)
200 .ok_or(ErrorCode::Limit)?;
201 let start = add(cursor, 512)?;
202 cursor = add(
203 start,
204 size.checked_add(511).ok_or(ErrorCode::Integrity)? / 512 * 512,
205 )?;
206 if cursor > len {
207 return Err(ErrorCode::Integrity);
208 }
209 metadata.charge(&name)?;
210 let name = archive::valid_name(&name, kind == EntryKind::Directory)?;
211 offsets.push(start);
212 members.push(Member {
213 entry: Entry {
214 entry_id: members.len() as u32,
215 name,
216 kind,
217 size,
218 compressed_size: size,
219 encrypted: false,
220 },
221 data: Vec::new(),
222 });
223 }
224 archive::validate_members(&members)?;
225 Ok(Catalog {
226 format,
227 members,
228 offsets,
229 data,
230 })
231}
232
233// ZIP 항목과 연결 GZip 스트림의 해제 총량을 제한함.
234fn inflate(
235 input: &mut impl Read,
236 length: u64,
237 gzip: bool,
238 limit: u64,
239 output: &mut File,
240 check: &mut impl FnMut() -> Result<()>,
241) -> Result<(u64, u32)> {
242 let mut remaining = length;
243 let mut buffer = Zeroizing::new([0; CHUNK]);
244 let mut plain = Zeroizing::new([0; CHUNK]);
245 let mut have = 0;
246 let mut used = 0;
247 let mut total = 0u64;
248 let mut crc = 0;
249 loop {
250 let mut stream = Inflate::new(gzip, if gzip { 31 } else { 15 });
251 loop {
252 check()?;
253 if used == have && remaining != 0 {
254 have = input
255 .read(&mut buffer[..remaining.min(CHUNK as u64) as usize])
256 .map_err(|_| ErrorCode::Io)?;
257 if have == 0 {
258 return Err(ErrorCode::Integrity);
259 }
260 remaining -= have as u64;
261 used = 0;
262 }
263 let a = stream.total_in();
264 let b = stream.total_out();
265 let status = stream
266 .decompress(&buffer[used..have], &mut plain[..], InflateFlush::NoFlush)
267 .map_err(|_| ErrorCode::Integrity)?;
268 used += (stream.total_in() - a) as usize;
269 let n = (stream.total_out() - b) as usize;
270 total = total
271 .checked_add(n as u64)
272 .filter(|n| *n <= limit)
273 .ok_or(ErrorCode::Limit)?;
274 crc = crc32(crc, &plain[..n]);
275 crate::space::ensure(output, n as u64)?;
276 io(output.write_all(&plain[..n]))?;
277 if status == Status::StreamEnd {
278 break;
279 }
280 if a == stream.total_in() && b == stream.total_out() {
281 return Err(ErrorCode::Integrity);
282 }
283 }
284 if remaining == 0 && used == have {
285 break;
286 }
287 if !gzip {
288 return Err(ErrorCode::Integrity);
289 }
290 }
291 Ok((total, crc))
292}
293
294struct Packed {
295 offset: u64,
296 size: u64,
297 method: u16,
298 crc: Option<u32>,
299 flags: u16,
300 verifier: u8,
301 aes: bool,
302}
303
304fn extra(bytes: &[u8]) -> Result<(Option<archive::AesExtra>, Option<Vec<u8>>)> {
305 let mut at = 0;
306 let mut aes = Vec::new();
307 let mut large = None;
308 while at < bytes.len() {
309 if bytes.len() - at < 4 {
310 return Err(ErrorCode::Integrity);
311 }
312 let tag = u16at(bytes, at);
313 let len = u16at(bytes, at + 2) as usize;
314 let end = at + 4 + len;
315 if end > bytes.len() {
316 return Err(ErrorCode::Integrity);
317 }
318 if tag == 1 {
319 if large.is_some() {
320 return Err(ErrorCode::Integrity);
321 }
322 large = Some(bytes[at + 4..end].to_vec());
323 } else {
324 aes.extend_from_slice(&bytes[at..end]);
325 }
326 at = end;
327 }
328 Ok((archive::aes_extra(&aes)?, large))
329}
330fn large_value(value: u32, extra: &mut &[u8]) -> Result<u64> {
331 if value != u32::MAX {
332 return Ok(value as u64);
333 }
334 if extra.len() < 8 {
335 return Err(ErrorCode::Integrity);
336 }
337 let result = u64at(extra, 0);
338 *extra = &extra[8..];
339 Ok(result)
340}
341fn expanded(value: u64, maximum: u64, large: u64) -> Result<u64> {
342 if value == maximum || value == large {
343 Ok(large)
344 } else {
345 Err(ErrorCode::Integrity)
346 }
347}
348fn disk_start(value: u16, extra: &mut &[u8]) -> Result<u32> {
349 if value != u16::MAX {
350 return Ok(value as u32);
351 }
352 if extra.len() < 4 {
353 return Err(ErrorCode::Integrity);
354 }
355 let result = u32at(extra, 0);
356 *extra = &extra[4..];
357 Ok(result)
358}
359fn local_sizes(size: u32, compressed: u32, extra: Option<&[u8]>) -> Result<(u64, u64)> {
360 if let Some(extra) = extra {
361 // 로컬 ZIP64 추가 필드에는 두 크기가 함께 들어감.
362 if extra.len() < 16 {
363 return Err(ErrorCode::Integrity);
364 }
365 Ok((
366 expanded(size as u64, u32::MAX as u64, u64at(extra, 0))?,
367 expanded(compressed as u64, u32::MAX as u64, u64at(extra, 8))?,
368 ))
369 } else if size == u32::MAX || compressed == u32::MAX {
370 Err(ErrorCode::Integrity)
371 } else {
372 Ok((size as u64, compressed as u64))
373 }
374}
375fn zip(
376 source: &mut File,
377 len: u64,
378 limits: Limits,
379 decode: bool,
380 password: Option<&[u8]>,
381 check: &mut impl FnMut() -> Result<()>,
382) -> Result<Catalog> {
383 if len < 22 {
384 return Err(ErrorCode::Integrity);
385 }
386 let tail_at = len.saturating_sub(65557);
387 let tail = bytes(source, tail_at, (len - tail_at) as usize)?;
388 let end = (0..=tail.len() - 22)
389 .rev()
390 .find(|&i| {
391 &tail[i..i + 4] == b"PK\x05\x06" && i + 22 + u16at(&tail, i + 20) as usize == tail.len()
392 })
393 .ok_or(ErrorCode::Integrity)?;
394 let h = &tail[end..];
395 let mut disk = u16at(h, 4) as u64;
396 let mut central_disk = u16at(h, 6) as u64;
397 let mut entries_on_disk = u16at(h, 8) as u64;
398 let mut count = u16at(h, 10) as u64;
399 let mut central_size = u32at(h, 12) as u64;
400 let mut central = u32at(h, 16) as u64;
401 let mut central_end = tail_at + end as u64;
402 let required_zip64 = [disk, central_disk, entries_on_disk, count].contains(&(u16::MAX as u64))
403 || central_size == u32::MAX as u64
404 || central == u32::MAX as u64;
405 let locator = if central_end >= 20 {
406 bytes(source, central_end - 20, 20)?
407 } else {
408 Vec::new()
409 };
410 // 중앙 디렉터리 주석의 동일 서명을 locator로 오인하지 않음
411 let has_locator =
412 locator.starts_with(b"PK\x06\x07") && add(central, central_size)? != central_end;
413 if required_zip64 || has_locator {
414 if locator.len() != 20 {
415 return Err(ErrorCode::Integrity);
416 }
417 if &locator[..4] != b"PK\x06\x07" || u32at(&locator, 4) != 0 || u32at(&locator, 16) != 1 {
418 return Err(ErrorCode::UnsupportedFeature);
419 }
420 let offset = u64at(&locator, 8);
421 if add(offset, 56)? > central_end - 20 {
422 return Err(ErrorCode::Integrity);
423 }
424 let large = bytes(source, offset, 56)?;
425 if &large[..4] != b"PK\x06\x06"
426 || u64at(&large, 4) < 44
427 || add(offset, add(12, u64at(&large, 4))?)? != central_end - 20
428 {
429 return Err(ErrorCode::Integrity);
430 }
431 // 각 필드의 확장값을 해석한 뒤 단일 디스크 조건을 검사함.
432 disk = expanded(disk, u16::MAX as u64, u32at(&large, 16) as u64)?;
433 central_disk = expanded(central_disk, u16::MAX as u64, u32at(&large, 20) as u64)?;
434 entries_on_disk = expanded(entries_on_disk, u16::MAX as u64, u64at(&large, 24))?;
435 count = expanded(count, u16::MAX as u64, u64at(&large, 32))?;
436 central_size = expanded(central_size, u32::MAX as u64, u64at(&large, 40))?;
437 central = expanded(central, u32::MAX as u64, u64at(&large, 48))?;
438 central_end = offset;
439 }
440 if disk != 0 || central_disk != 0 || entries_on_disk != count {
441 return Err(ErrorCode::UnsupportedFeature);
442 }
443 if count > limits.entries as u64 {
444 return Err(ErrorCode::Limit);
445 }
446 if add(central, central_size)? != central_end {
447 return Err(ErrorCode::Integrity);
448 }
449 let mut cursor = central;
450 let mut total = 0u64;
451 let mut metadata = MetadataBudget::default();
452 let mut members = Vec::new();
453 let mut packed = Vec::new();
454 let mut spans = Vec::new();
455 for id in 0..count {
456 check()?;
457 if add(cursor, 46)? > central_end {
458 return Err(ErrorCode::Integrity);
459 }
460 let h = bytes(source, cursor, 46)?;
461 if &h[..4] != b"PK\x01\x02" {
462 return Err(ErrorCode::Integrity);
463 }
464 let flags = u16at(&h, 8);
465 let method = u16at(&h, 10);
466 if flags & !0x080f != 0 || !matches!(method, 0 | 8 | 99) {
467 return Err(ErrorCode::UnsupportedFeature);
468 }
469 let crc = u32at(&h, 16);
470 let (nn, ne, nc) = (
471 u16at(&h, 28) as u64,
472 u16at(&h, 30) as u64,
473 u16at(&h, 32) as u64,
474 );
475 let next = add(cursor, 46 + nn + ne + nc)?;
476 if next > central_end {
477 return Err(ErrorCode::Integrity);
478 }
479 if nn > 4096 {
480 return Err(ErrorCode::UnsafePath);
481 }
482 let raw = bytes(source, cursor + 46, nn as usize)?;
483 if flags & 0x0800 == 0 && !raw.is_ascii() {
484 return Err(ErrorCode::UnsupportedFeature);
485 }
486 let name = std::str::from_utf8(&raw).map_err(|_| ErrorCode::Integrity)?;
487 let (aes, large) = extra(&bytes(source, cursor + 46 + nn, ne as usize)?)?;
488 let mut large = large.as_deref().unwrap_or(&[]);
489 let size = large_value(u32at(&h, 24), &mut large)?;
490 let compressed = large_value(u32at(&h, 20), &mut large)?;
491 let local = large_value(u32at(&h, 42), &mut large)?;
492 if disk_start(u16at(&h, 34), &mut large)? != 0 {
493 return Err(ErrorCode::UnsupportedFeature);
494 }
495 let encrypted = flags & 1 != 0;
496 if (method == 99) != aes.is_some()
497 || (method == 99 && !encrypted)
498 || (aes.is_some_and(|a| a.version == 2) && crc != 0)
499 {
500 return Err(ErrorCode::Integrity);
501 }
502 let overhead = if !encrypted {
503 0
504 } else if aes.is_some() {
505 28
506 } else {
507 12
508 };
509 compressed
510 .checked_sub(overhead)
511 .ok_or(ErrorCode::Integrity)?;
512 total = total
513 .checked_add(size)
514 .filter(|n| *n <= limits.output)
515 .ok_or(ErrorCode::Limit)?;
516 let mode = u32at(&h, 38) >> 16;
517 let kind = match mode & 0xf000 {
518 0xa000 => EntryKind::Link,
519 0x4000 => EntryKind::Directory,
520 0 | 0x8000 => {
521 if name.ends_with('/') {
522 EntryKind::Directory
523 } else {
524 EntryKind::File
525 }
526 }
527 _ => EntryKind::Other,
528 };
529 if kind == EntryKind::Directory && size != 0 {
530 return Err(ErrorCode::Integrity);
531 }
532 metadata.charge(name)?;
533 let name = archive::valid_name(name, kind == EntryKind::Directory)?;
534 if add(local, 30)? > central {
535 return Err(ErrorCode::Integrity);
536 }
537 let lh = bytes(source, local, 30)?;
538 if &lh[..4] != b"PK\x03\x04"
539 || u16at(&lh, 6) != flags
540 || u16at(&lh, 8) != method
541 || u16at(&lh, 10) != u16at(&h, 12)
542 {
543 return Err(ErrorCode::Integrity);
544 }
545 let (ln, le) = (u16at(&lh, 26) as u64, u16at(&lh, 28) as u64);
546 let start = add(local, 30 + ln + le)?;
547 if start > central || ln != nn {
548 return Err(ErrorCode::Integrity);
549 }
550 if bytes(source, local + 30, ln as usize)? != raw {
551 return Err(ErrorCode::Integrity);
552 }
553 let (local_aes, local_large) = extra(&bytes(source, local + 30 + ln, le as usize)?)?;
554 if local_aes != aes || local_large.as_ref().is_some_and(|values| values.len() < 16) {
555 return Err(ErrorCode::Integrity);
556 }
557 let size_zip64 = u32at(&h, 20) == u32::MAX
558 || u32at(&h, 24) == u32::MAX
559 || u32at(&lh, 18) == u32::MAX
560 || u32at(&lh, 22) == u32::MAX
561 || local_large.is_some();
562 if flags & 8 == 0 {
563 let (local_size, local_compressed) =
564 local_sizes(u32at(&lh, 22), u32at(&lh, 18), local_large.as_deref())?;
565 if u32at(&lh, 14) != crc || local_size != size || local_compressed != compressed {
566 return Err(ErrorCode::Integrity);
567 }
568 }
569 let mut stop = add(start, compressed)?;
570 if stop > central {
571 return Err(ErrorCode::Integrity);
572 }
573 if flags & 8 != 0 {
574 let descriptor_len = if size_zip64 { 20 } else { 12 };
575 if add(stop, descriptor_len)? > central {
576 return Err(ErrorCode::Integrity);
577 }
578 let signature = bytes(source, stop, 4)?;
579 if signature == b"PK\x07\x08" {
580 stop = add(stop, 4)?;
581 }
582 if add(stop, descriptor_len)? > central {
583 return Err(ErrorCode::Integrity);
584 }
585 let d = bytes(source, stop, descriptor_len as usize)?;
586 let (pc, ps) = if size_zip64 {
587 (u64at(&d, 4), u64at(&d, 12))
588 } else {
589 (u32at(&d, 4) as u64, u32at(&d, 8) as u64)
590 };
591 if u32at(&d, 0) != crc || pc != compressed || ps != size {
592 return Err(ErrorCode::Integrity);
593 }
594 stop += descriptor_len;
595 }
596 spans.push((local, stop));
597 packed.push(Packed {
598 offset: start,
599 size: compressed,
600 method: aes.map_or(method, |a| a.method),
601 crc: if aes.is_some_and(|a| a.version == 2) {
602 None
603 } else {
604 Some(crc)
605 },
606 flags,
607 verifier: if flags & 8 != 0 {
608 (u16at(&h, 12) >> 8) as u8
609 } else {
610 (crc >> 24) as u8
611 },
612 aes: aes.is_some(),
613 });
614 members.push(Member {
615 entry: Entry {
616 entry_id: id as u32,
617 name,
618 kind,
619 size,
620 compressed_size: compressed,
621 encrypted,
622 },
623 data: Vec::new(),
624 });
625 cursor = next;
626 }
627 if cursor != central_end {
628 return Err(ErrorCode::Integrity);
629 }
630 spans.sort_unstable();
631 let mut next = 0;
632 for (a, b) in spans {
633 if a != next {
634 return Err(ErrorCode::Integrity);
635 }
636 next = b;
637 }
638 if next != central {
639 return Err(ErrorCode::Integrity);
640 }
641 archive::validate_members(&members)?;
642 let mut data = spool::temporary()?;
643 if decode {
644 crate::space::ensure(&data, total)?;
645 }
646 let mut offsets = Vec::new();
647 for (member, packed) in members.iter().zip(packed) {
648 check()?;
649 offsets.push(io(data.stream_position())?);
650 if !decode {
651 continue;
652 }
653 let (decoder, start, length) = if packed.flags & 1 != 0 {
654 crypto::Decryptor::prepare(
655 source,
656 packed.offset,
657 packed.size,
658 password.ok_or(ErrorCode::WrongPassword)?,
659 packed.aes,
660 packed.verifier,
661 check,
662 )?
663 } else {
664 (crypto::Decryptor::Plain, packed.offset, packed.size)
665 };
666 io(source.seek(SeekFrom::Start(start)))?;
667 let mut reader = Decoded {
668 reader: source.take(length),
669 decoder,
670 };
671 let (size, crc) = if packed.method == 8 {
672 inflate(
673 &mut reader,
674 length,
675 false,
676 member.entry.size,
677 &mut data,
678 check,
679 )?
680 } else {
681 let mut buffer = Zeroizing::new([0; CHUNK]);
682 let mut total = 0u64;
683 let mut crc = 0;
684 loop {
685 check()?;
686 let n = io(reader.read(&mut buffer[..]))?;
687 if n == 0 {
688 break;
689 }
690 total = total
691 .checked_add(n as u64)
692 .filter(|n| *n <= member.entry.size)
693 .ok_or(ErrorCode::Integrity)?;
694 crc = crc32(crc, &buffer[..n]);
695 io(data.write_all(&buffer[..n]))?;
696 }
697 (total, crc)
698 };
699 if size != member.entry.size || packed.crc.is_some_and(|c| c != crc) {
700 return Err(ErrorCode::Integrity);
701 }
702 }
703 Ok(Catalog {
704 format: Format::Zip,
705 members,
706 offsets,
707 data,
708 })
709}
710struct Decoded<R> {
711 reader: R,
712 decoder: crypto::Decryptor,
713}
714impl<R: Read> Read for Decoded<R> {
715 fn read(&mut self, output: &mut [u8]) -> std::io::Result<usize> {
716 let n = self.reader.read(output)?;
717 self.decoder.apply(&mut output[..n]);
718 Ok(n)
719 }
720}
721
722#[cfg(test)]
723#[path = "../../../tests/rust-archive-worker/streaming_bounds.rs"]
724mod bounds;