team-ljyzipelo

공개

ZIP 주석의 ZIP64 locator 오인을 수정함

작성자
시로사키 하나
작성 시각
커밋
86cb30a6d67a10ae4670a804974a3f3c251e8b49
부모
adf78d3
이 시점의 파일 보기

변경된 파일 3개

+71-2
수정experiments/rust-archive-worker/src/zip_recovery.rs+7-2
@@ -160,10 +160,15 @@ fn central(
160160 }
161161 let cd = u32at(h, 16) as u64;
162162 let cd_end = tail_at + end as u64;
163삭제: if cd_end >= 20 && bytes(source, cd_end - 20, 4, len)? == b"PK\x06\x07" {
163추가: let declared_cd_end = add(cd, u32at(h, 12) as u64)?;
164추가: // 중앙 목록의 주석을 ZIP64 locator로 오인하지 않음.
165추가: if cd_end >= 20
166추가: && declared_cd_end <= cd_end - 20
167추가: && bytes(source, cd_end - 20, 4, len)? == b"PK\x06\x07"
168추가: {
164169 return Err(ErrorCode::UnsupportedFeature);
165170 }
166삭제: if add(cd, u32at(h, 12) as u64)? != cd_end {
171추가: if declared_cd_end != cd_end {
167172 return Err(ErrorCode::Integrity);
168173 }
169174 if count > limits.entries {
수정tests/rust-archive-worker/recovery.rs+47-0
@@ -495,3 +495,50 @@ fn recovery_publication_rechecks_source_destination_and_cancel() {
495495 }
496496 }
497497}
498추가:
499추가: #[test]
500추가: fn central_comment_locator_bytes_do_not_reject_zip32_recovery() {
501추가: let source = include_bytes!("../zip-recovery-fixtures/broken-local-header.zip");
502추가: for comment_len in [20usize, 37] {
503추가: for archive_comment_len in [0usize, 41] {
504추가: let mut input = source[..source.len() - 22].to_vec();
505추가: let last = input.windows(4).rposition(|w| w == b"PK\x01\x02").unwrap();
506추가: input[last + 32..last + 34].copy_from_slice(&(comment_len as u16).to_le_bytes());
507추가: let mut comment = vec![0; comment_len];
508추가: comment[comment_len - 20..comment_len - 16].copy_from_slice(b"PK\x06\x07");
509추가: input.extend(comment);
510추가: let mut end = source[source.len() - 22..].to_vec();
511추가: let size = u32::from_le_bytes(end[12..16].try_into().unwrap());
512추가: end[12..16].copy_from_slice(&(size + comment_len as u32).to_le_bytes());
513추가: end[20..22].copy_from_slice(&(archive_comment_len as u16).to_le_bytes());
514추가: input.extend(end);
515추가: input.extend(vec![0; archive_comment_len]);
516추가: let s = Scratch::new();
517추가: fs::write(s.0.join("damaged.zip"), &input).unwrap();
518추가: let events = execute(start(&s));
519추가: let t = terminal(&events);
520추가: assert_eq!(t.error, ErrorCode::None);
521추가: assert_eq!(t.outcome, Outcome::Completed);
522추가: assert_eq!(t.publication, Publication::Complete);
523추가: assert_eq!(t.created_count, 1);
524추가: let end = recovery_end(&events);
525추가: assert!(end.complete());
526추가: assert_eq!(end.verified_entries, 6);
527추가: assert_eq!(end.source_sha256, <[u8; 32]>::from(Sha256::digest(&input)));
528추가: assert_eq!(fs::read(s.0.join("damaged.zip")).unwrap(), input);
529추가: assert!(
530추가: Command::new("python3")
531추가: .arg("-B")
532추가: .arg(
533추가: PathBuf::from(env!("CARGO_MANIFEST_DIR"))
534추가: .join("../../tests/zip-recovery-fixtures/verify.py")
535추가: )
536추가: .args(["--recovered", "broken-local-header.zip"])
537추가: .arg(s.0.join("recovered.zip"))
538추가: .status()
539추가: .unwrap()
540추가: .success()
541추가: );
542추가: }
543추가: }
544추가: }
수정tests/rust-archive-worker/recovery_checks.rs+17-0
@@ -209,3 +209,20 @@ fn decoder_error_bytes_are_charged_before_reporting_loss() {
209209 ));
210210 assert_eq!(used, count);
211211}
212추가:
213추가: #[test]
214추가: fn zip64_locator_after_central_directory_remains_unsupported() {
215추가: let source = include_bytes!("../zip-recovery-fixtures/broken-local-header.zip");
216추가: let mut input = source[..source.len() - 22].to_vec();
217추가: input.extend(b"PK\x06\x07");
218추가: input.extend(0u32.to_le_bytes());
219추가: input.extend(0u64.to_le_bytes());
220추가: input.extend(1u32.to_le_bytes());
221추가: input.extend(&source[source.len() - 22..]);
222추가: let s = Scratch::new(&input);
223추가: assert!(matches!(
224추가: Recovery::open(&s.path(), Limits::default(), &mut || Ok(())),
225추가: Err(ErrorCode::UnsupportedFeature)
226추가: ));
227추가: assert_eq!(std::fs::read(s.path()).unwrap(), input);
228추가: }