team-ljyzipelo

공개

강제 ZIP64 디스크립터 호환성을 보완함

작성자
시로사키 하나
작성 시각
커밋
fce3995908f006106c5b37f1a9674335de8dd4db
부모
865ac8f
이 시점의 파일 보기

변경된 파일 2개

+70-13
수정experiments/rust-archive-worker/src/streaming.rs+28-13
@@ -372,6 +372,31 @@ fn local_sizes(size: u32, compressed: u32, extra: Option<&[u8]>) -> Result<(u64,
372372 Ok((size as u64, compressed as u64))
373373 }
374374}
375추가: fn descriptor_size(
376추가: bytes: &[u8],
377추가: crc: u32,
378추가: compressed: u64,
379추가: size: u64,
380추가: wide_required: bool,
381추가: ) -> Result<usize> {
382추가: // 일반 크기 헤더와 64비트 디스크립터를 함께 기록하는 도구도 있음.
383추가: if bytes.len() >= 20
384추가: && u32at(bytes, 0) == crc
385추가: && u64at(bytes, 4) == compressed
386추가: && u64at(bytes, 12) == size
387추가: {
388추가: return Ok(20);
389추가: }
390추가: if !wide_required
391추가: && bytes.len() >= 12
392추가: && u32at(bytes, 0) == crc
393추가: && u32at(bytes, 4) as u64 == compressed
394추가: && u32at(bytes, 8) as u64 == size
395추가: {
396추가: return Ok(12);
397추가: }
398추가: Err(ErrorCode::Integrity)
399추가: }
375400fn zip(
376401 source: &mut File,
377402 len: u64,
@@ -579,19 +604,9 @@ fn zip(
579604 if signature == b"PK\x07\x08" {
580605 stop = add(stop, 4)?;
581606 }
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;
607추가: let d = bytes(source, stop, (central - stop).min(20) as usize)?;
608추가: let descriptor_len = descriptor_size(&d, crc, compressed, size, size_zip64)?;
609추가: stop = add(stop, descriptor_len as u64)?;
595610 }
596611 spans.push((local, stop));
597612 packed.push(Packed {
수정tests/rust-archive-worker/streaming_bounds.rs+42-0
@@ -80,3 +80,45 @@ fn local_zip64_always_reads_both_sizes() {
8080 );
8181 }
8282}
83추가:
84추가: #[test]
85추가: fn descriptor_width_uses_sizes_and_crc() {
86추가: for (compressed, size) in [(21u64, 21u64), (0, 0)] {
87추가: let crc = 123u32;
88추가: let wide = [
89추가: crc.to_le_bytes().as_slice(),
90추가: &compressed.to_le_bytes(),
91추가: &size.to_le_bytes(),
92추가: ]
93추가: .concat();
94추가: let narrow = [
95추가: crc.to_le_bytes(),
96추가: (compressed as u32).to_le_bytes(),
97추가: (size as u32).to_le_bytes(),
98추가: ]
99추가: .concat();
100추가: assert_eq!(descriptor_size(&wide, crc, compressed, size, false), Ok(20));
101추가: assert_eq!(descriptor_size(&wide, crc, compressed, size, true), Ok(20));
102추가: assert_eq!(
103추가: descriptor_size(&narrow, crc, compressed, size, false),
104추가: Ok(12)
105추가: );
106추가: assert_eq!(
107추가: descriptor_size(&narrow, crc, compressed, size, true),
108추가: Err(ErrorCode::Integrity)
109추가: );
110추가: let followed = [narrow.as_slice(), b"PK\x03\x04\x14\0\0\0"].concat();
111추가: assert_eq!(
112추가: descriptor_size(&followed, crc, compressed, size, false),
113추가: Ok(12)
114추가: );
115추가: assert_eq!(
116추가: descriptor_size(&wide, crc + 1, compressed, size, false),
117추가: Err(ErrorCode::Integrity)
118추가: );
119추가: assert_eq!(
120추가: descriptor_size(&wide[..11], crc, compressed, size, false),
121추가: Err(ErrorCode::Integrity)
122추가: );
123추가: }
124추가: }