| | @@ -495,3 +495,50 @@ fn recovery_publication_rechecks_source_destination_and_cancel() { |
| 495 | 495 | } |
| 496 | 496 | } |
| 497 | 497 | } |
| 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 | +추가: } |