Merge pull request #75 from Team-LJY/fix/zip64-compat-corpus
ZIP64 도구 원본과 부분 확장 조합 회귀 시험 추가
- 작성자
- LeeJunyoung
- 작성 시각
- 커밋
bbcaed9698ecba917be965f15f9b749f3b9d1cbe
변경된 파일 7개
+603-0| @@ -0,0 +1,2 @@ | ||
| 1 | 추가: /runs/ | |
| 2 | 추가: /target/ |
| @@ -0,0 +1,187 @@ | ||
| 1 | 추가: # This file is automatically @generated by Cargo. | |
| 2 | 추가: # It is not intended for manual editing. | |
| 3 | 추가: version = 4 | |
| 4 | 추가: | |
| 5 | 추가: [[package]] | |
| 6 | 추가: name = "aes" | |
| 7 | 추가: version = "0.8.4" | |
| 8 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 9 | 추가: checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" | |
| 10 | 추가: dependencies = [ | |
| 11 | 추가: "cfg-if", | |
| 12 | 추가: "cipher", | |
| 13 | 추가: "cpufeatures", | |
| 14 | 추가: "zeroize", | |
| 15 | 추가: ] | |
| 16 | 추가: | |
| 17 | 추가: [[package]] | |
| 18 | 추가: name = "block-buffer" | |
| 19 | 추가: version = "0.10.4" | |
| 20 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 21 | 추가: checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" | |
| 22 | 추가: dependencies = [ | |
| 23 | 추가: "generic-array", | |
| 24 | 추가: ] | |
| 25 | 추가: | |
| 26 | 추가: [[package]] | |
| 27 | 추가: name = "cfg-if" | |
| 28 | 추가: version = "1.0.5" | |
| 29 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 30 | 추가: checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" | |
| 31 | 추가: | |
| 32 | 추가: [[package]] | |
| 33 | 추가: name = "cipher" | |
| 34 | 추가: version = "0.4.4" | |
| 35 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 36 | 추가: checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" | |
| 37 | 추가: dependencies = [ | |
| 38 | 추가: "crypto-common", | |
| 39 | 추가: "inout", | |
| 40 | 추가: ] | |
| 41 | 추가: | |
| 42 | 추가: [[package]] | |
| 43 | 추가: name = "cpufeatures" | |
| 44 | 추가: version = "0.2.17" | |
| 45 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 46 | 추가: checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" | |
| 47 | 추가: dependencies = [ | |
| 48 | 추가: "libc", | |
| 49 | 추가: ] | |
| 50 | 추가: | |
| 51 | 추가: [[package]] | |
| 52 | 추가: name = "crypto-common" | |
| 53 | 추가: version = "0.1.7" | |
| 54 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 55 | 추가: checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" | |
| 56 | 추가: dependencies = [ | |
| 57 | 추가: "generic-array", | |
| 58 | 추가: "typenum", | |
| 59 | 추가: ] | |
| 60 | 추가: | |
| 61 | 추가: [[package]] | |
| 62 | 추가: name = "digest" | |
| 63 | 추가: version = "0.10.7" | |
| 64 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 65 | 추가: checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" | |
| 66 | 추가: dependencies = [ | |
| 67 | 추가: "block-buffer", | |
| 68 | 추가: "crypto-common", | |
| 69 | 추가: "subtle", | |
| 70 | 추가: ] | |
| 71 | 추가: | |
| 72 | 추가: [[package]] | |
| 73 | 추가: name = "generic-array" | |
| 74 | 추가: version = "0.14.7" | |
| 75 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 76 | 추가: checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" | |
| 77 | 추가: dependencies = [ | |
| 78 | 추가: "typenum", | |
| 79 | 추가: "version_check", | |
| 80 | 추가: ] | |
| 81 | 추가: | |
| 82 | 추가: [[package]] | |
| 83 | 추가: name = "hmac" | |
| 84 | 추가: version = "0.12.1" | |
| 85 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 86 | 추가: checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" | |
| 87 | 추가: dependencies = [ | |
| 88 | 추가: "digest", | |
| 89 | 추가: ] | |
| 90 | 추가: | |
| 91 | 추가: [[package]] | |
| 92 | 추가: name = "inout" | |
| 93 | 추가: version = "0.1.4" | |
| 94 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 95 | 추가: checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" | |
| 96 | 추가: dependencies = [ | |
| 97 | 추가: "generic-array", | |
| 98 | 추가: ] | |
| 99 | 추가: | |
| 100 | 추가: [[package]] | |
| 101 | 추가: name = "libc" | |
| 102 | 추가: version = "0.2.191" | |
| 103 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 104 | 추가: checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" | |
| 105 | 추가: | |
| 106 | 추가: [[package]] | |
| 107 | 추가: name = "pbkdf2" | |
| 108 | 추가: version = "0.12.2" | |
| 109 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 110 | 추가: checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" | |
| 111 | 추가: dependencies = [ | |
| 112 | 추가: "digest", | |
| 113 | 추가: "hmac", | |
| 114 | 추가: ] | |
| 115 | 추가: | |
| 116 | 추가: [[package]] | |
| 117 | 추가: name = "sha1" | |
| 118 | 추가: version = "0.10.7" | |
| 119 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 120 | 추가: checksum = "a978451301f4db1d02937a4ab3ccce137717b81826e79b7d49ffe3244a13c3b8" | |
| 121 | 추가: dependencies = [ | |
| 122 | 추가: "cfg-if", | |
| 123 | 추가: "cpufeatures", | |
| 124 | 추가: "digest", | |
| 125 | 추가: ] | |
| 126 | 추가: | |
| 127 | 추가: [[package]] | |
| 128 | 추가: name = "sha2" | |
| 129 | 추가: version = "0.10.9" | |
| 130 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 131 | 추가: checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" | |
| 132 | 추가: dependencies = [ | |
| 133 | 추가: "cfg-if", | |
| 134 | 추가: "cpufeatures", | |
| 135 | 추가: "digest", | |
| 136 | 추가: ] | |
| 137 | 추가: | |
| 138 | 추가: [[package]] | |
| 139 | 추가: name = "subtle" | |
| 140 | 추가: version = "2.6.1" | |
| 141 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 142 | 추가: checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" | |
| 143 | 추가: | |
| 144 | 추가: [[package]] | |
| 145 | 추가: name = "typenum" | |
| 146 | 추가: version = "1.20.1" | |
| 147 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 148 | 추가: checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" | |
| 149 | 추가: | |
| 150 | 추가: [[package]] | |
| 151 | 추가: name = "version_check" | |
| 152 | 추가: version = "0.9.5" | |
| 153 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 154 | 추가: checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" | |
| 155 | 추가: | |
| 156 | 추가: [[package]] | |
| 157 | 추가: name = "zeroize" | |
| 158 | 추가: version = "1.9.1" | |
| 159 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 160 | 추가: checksum = "e13084392c5e4bc371903e2935a5eaeed24905a7511356b883835e18a78f6879" | |
| 161 | 추가: | |
| 162 | 추가: [[package]] | |
| 163 | 추가: name = "zipelo-archive-worker" | |
| 164 | 추가: version = "0.1.0" | |
| 165 | 추가: dependencies = [ | |
| 166 | 추가: "aes", | |
| 167 | 추가: "hmac", | |
| 168 | 추가: "pbkdf2", | |
| 169 | 추가: "sha1", | |
| 170 | 추가: "sha2", | |
| 171 | 추가: "subtle", | |
| 172 | 추가: "zeroize", | |
| 173 | 추가: "zlib-rs", | |
| 174 | 추가: ] | |
| 175 | 추가: | |
| 176 | 추가: [[package]] | |
| 177 | 추가: name = "zipelo-zip64-compat" | |
| 178 | 추가: version = "0.1.0" | |
| 179 | 추가: dependencies = [ | |
| 180 | 추가: "zipelo-archive-worker", | |
| 181 | 추가: ] | |
| 182 | 추가: | |
| 183 | 추가: [[package]] | |
| 184 | 추가: name = "zlib-rs" | |
| 185 | 추가: version = "0.6.8" | |
| 186 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 187 | 추가: checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112" |
| @@ -0,0 +1,22 @@ | ||
| 1 | 추가: [package] | |
| 2 | 추가: name = "zipelo-zip64-compat" | |
| 3 | 추가: version = "0.1.0" | |
| 4 | 추가: edition = "2024" | |
| 5 | 추가: license = "MIT" | |
| 6 | 추가: publish = false | |
| 7 | 추가: autotests = false | |
| 8 | 추가: | |
| 9 | 추가: [workspace] | |
| 10 | 추가: | |
| 11 | 추가: [dependencies] | |
| 12 | 추가: zipelo-archive-worker = { path = "../../experiments/rust-archive-worker" } | |
| 13 | 추가: | |
| 14 | 추가: [[bin]] | |
| 15 | 추가: name = "zip64-test-worker" | |
| 16 | 추가: path = "worker.rs" | |
| 17 | 추가: test = false | |
| 18 | 추가: bench = false | |
| 19 | 추가: | |
| 20 | 추가: [[test]] | |
| 21 | 추가: name = "zip64_corpus" | |
| 22 | 추가: path = "corpus.rs" |
| @@ -0,0 +1,51 @@ | ||
| 1 | 추가: # ZIP64 호환 표본 | |
| 2 | 추가: | |
| 3 | 추가: PR74의 스트리밍 작업자를 실제 자식 프로세스로 실행해 모든 표본의 목록과 해제를 확인함. | |
| 4 | 추가: 제품 구현 변경 없이 별도 시험 crate에서 공개 runtime과 wire codec을 사용함. | |
| 5 | 추가: 표본과 결과는 실행 시 runs/에 생성하며 저장소에는 압축파일을 넣지 않음. | |
| 6 | 추가: | |
| 7 | 추가: ## 구성 | |
| 8 | 추가: | |
| 9 | 추가: 총 1066개이며 모든 기대 결과는 목록과 해제 성공임. | |
| 10 | 추가: | |
| 11 | 추가: - 원본 5개: Python 일반 ZIP, Python force_zip64의 탐색 가능/불가능 출력, libarchive zip64=1, Info-ZIP -fz 일반 파일 출력. | |
| 12 | 추가: - 필드 조합 1024개: 중앙 디렉터리의 원래 크기, 압축 크기, 로컬 오프셋, 시작 디스크 번호 16조합과 EOCD의 현재 디스크, 중앙 시작 디스크, 디스크 내 항목 수, 전체 항목 수, 중앙 크기, 중앙 오프셋 64조합의 곱. | |
| 13 | 추가: - 로컬 크기 두 필드가 함께 확장된 중앙 필드 조합 16개. | |
| 14 | 추가: - ZIP64 종료 레코드 없이 중앙 필드만 확장한 조합 16개. | |
| 15 | 추가: - 기존 회귀 표본 5개: 260바이트 강제 ZIP64, 서명 유무별 오프셋 전용 32비트 디스크립터, EOCD 디스크 번호 확장, 중앙 시작 디스크 번호 확장. | |
| 16 | 추가: | |
| 17 | 추가: fields-cXX-eYY의 마스크 비트는 위 필드 나열 순서이며 최하위 비트부터 적용함. | |
| 18 | 추가: 디스크 번호의 실제 값은 항상 0이고 항목 수는 1임. | |
| 19 | 추가: 4 GiB 파일을 만들지 않고 sentinel을 사용해 작은 값의 확장 표현을 검사함. | |
| 20 | 추가: 실제 4 GiB 초과 오프셋, 다중 볼륨, 암호 ZIP은 이 묶음의 범위가 아님. | |
| 21 | 추가: | |
| 22 | 추가: [APPNOTE 6.3.10](https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT)의 | |
| 23 | 추가: 4.4.13, 4.4.19~4.4.24, 4.5.3을 기준으로 대응 필드가 sentinel인 경우에만 | |
| 24 | 추가: 중앙 ZIP64 확장값을 순서대로 넣음. 로컬 크기 확장은 두 크기 값을 함께 넣음. | |
| 25 | 추가: 도구 원본과 수동 필드 변형은 provenance.json에서 구분함. | |
| 26 | 추가: Info-ZIP은 -fz와 stdout을 함께 사용할 때 이 환경에서 손상된 종료 레코드를 만들므로 | |
| 27 | 추가: 정상 일반 파일 출력에 -fz를 적용함. | |
| 28 | 추가: | |
| 29 | 추가: ## 실행과 판정 | |
| 30 | 추가: | |
| 31 | 추가: Linux에서 Python 3, Info-ZIP zip, 시스템 libarchive가 필요함. | |
| 32 | 추가: 누락된 도구나 참조 판독 실패는 성공으로 건너뛰지 않음. | |
| 33 | 추가: 제품의 추가 의존성은 없음. | |
| 34 | 추가: | |
| 35 | 추가: ```sh | |
| 36 | 추가: cargo +1.99.1 test --manifest-path tests/rust-zip64-compat/Cargo.toml --locked -- --nocapture | |
| 37 | 추가: python3 tests/ci/run_rust.py local | |
| 38 | 추가: ``` | |
| 39 | 추가: | |
| 40 | 추가: 지정 실행기는 tests/*/Cargo.toml을 검색하므로 별도 실행기 설정 없이 포함됨. | |
| 41 | 추가: Windows 교차 빌드는 수행하지만 이 표본 실행 시험은 Linux 전용임. | |
| 42 | 추가: | |
| 43 | 추가: Python zipfile로 전체 표본의 내용과 CRC를 먼저 확인함. | |
| 44 | 추가: 작업자 목록의 이름, 크기, ListId와 해제 결과의 전체 바이트, 게시 수, 정리 상태를 확인함. | |
| 45 | 추가: 일부 표본이 실패해도 나머지를 계속 실행하고 마지막에 시험을 실패시킴. | |
| 46 | 추가: runs/<실행 ID>/results.tsv에 모든 표본의 목록/해제 결과가 남음. | |
| 47 | 추가: 같은 위치의 corpus/provenance.json에는 도구 버전과 표본 출처가 남음. | |
| 48 | 추가: | |
| 49 | 추가: ZIPELO_ZIP64_WORKER 환경 변수로 비교할 작업자 실행 파일을 지정할 수 있음. | |
| 50 | 추가: 기본값은 같은 worker 의존성으로 빌드한 zip64-test-worker임. | |
| 51 | 추가: 이 환경 변수는 시험 코드에만 적용되며 제품 작업자에는 적용되지 않음. |
| @@ -0,0 +1,161 @@ | ||
| 1 | 추가: #![cfg(target_os = "linux")] | |
| 2 | 추가: | |
| 3 | 추가: use std::{ | |
| 4 | 추가: fs, | |
| 5 | 추가: io::Write, | |
| 6 | 추가: path::{Path, PathBuf}, | |
| 7 | 추가: process::{Command, Stdio}, | |
| 8 | 추가: time::{SystemTime, UNIX_EPOCH}, | |
| 9 | 추가: }; | |
| 10 | 추가: use zipelo_archive_worker::{ | |
| 11 | 추가: protocol::*, | |
| 12 | 추가: wire::{Reader, Writer}, | |
| 13 | 추가: }; | |
| 14 | 추가: | |
| 15 | 추가: fn execute(action: Action) -> Vec<Message> { | |
| 16 | 추가: let mut request = Vec::new(); | |
| 17 | 추가: Writer::new(&mut request, 17) | |
| 18 | 추가: .send(&Message::Start(Start { | |
| 19 | 추가: action, | |
| 20 | 추가: limits: Limits::default(), | |
| 21 | 추가: })) | |
| 22 | 추가: .unwrap(); | |
| 23 | 추가: let worker = std::env::var_os("ZIPELO_ZIP64_WORKER") | |
| 24 | 추가: .unwrap_or_else(|| env!("CARGO_BIN_EXE_zip64-test-worker").into()); | |
| 25 | 추가: let mut child = Command::new(worker) | |
| 26 | 추가: .stdin(Stdio::piped()) | |
| 27 | 추가: .stdout(Stdio::piped()) | |
| 28 | 추가: .stderr(Stdio::piped()) | |
| 29 | 추가: .spawn() | |
| 30 | 추가: .unwrap(); | |
| 31 | 추가: child.stdin.take().unwrap().write_all(&request).unwrap(); | |
| 32 | 추가: let output = child.wait_with_output().unwrap(); | |
| 33 | 추가: assert!(output.status.success(), "{:?}", output.stderr); | |
| 34 | 추가: assert!(output.stderr.is_empty()); | |
| 35 | 추가: let mut reader = Reader::new(output.stdout.as_slice()); | |
| 36 | 추가: let mut events = Vec::new(); | |
| 37 | 추가: while let Some((job, _, event)) = reader.read().unwrap() { | |
| 38 | 추가: assert_eq!(job, 17); | |
| 39 | 추가: assert!(!matches!(events.last(), Some(Message::Terminal(_)))); | |
| 40 | 추가: events.push(event); | |
| 41 | 추가: } | |
| 42 | 추가: assert!(matches!(events.last(), Some(Message::Terminal(_)))); | |
| 43 | 추가: events | |
| 44 | 추가: } | |
| 45 | 추가: | |
| 46 | 추가: fn terminal(events: &[Message]) -> &Terminal { | |
| 47 | 추가: match events.last().unwrap() { | |
| 48 | 추가: Message::Terminal(value) => value, | |
| 49 | 추가: _ => unreachable!(), | |
| 50 | 추가: } | |
| 51 | 추가: } | |
| 52 | 추가: | |
| 53 | 추가: fn directory(path: &Path) { | |
| 54 | 추가: use std::os::unix::fs::DirBuilderExt; | |
| 55 | 추가: fs::DirBuilder::new().mode(0o700).create(path).unwrap(); | |
| 56 | 추가: } | |
| 57 | 추가: | |
| 58 | 추가: #[test] | |
| 59 | 추가: fn zip64_tool_and_field_corpus_lists_and_extracts() { | |
| 60 | 추가: let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")); | |
| 61 | 추가: let runs = root.join("runs"); | |
| 62 | 추가: fs::create_dir_all(&runs).unwrap(); | |
| 63 | 추가: let scratch = runs.join(format!( | |
| 64 | 추가: "{}-{}", | |
| 65 | 추가: std::process::id(), | |
| 66 | 추가: SystemTime::now() | |
| 67 | 추가: .duration_since(UNIX_EPOCH) | |
| 68 | 추가: .unwrap() | |
| 69 | 추가: .as_nanos() | |
| 70 | 추가: )); | |
| 71 | 추가: directory(&scratch); | |
| 72 | 추가: let corpus = scratch.join("corpus"); | |
| 73 | 추가: assert!( | |
| 74 | 추가: Command::new("python3") | |
| 75 | 추가: .arg(root.join("generate.py")) | |
| 76 | 추가: .arg(&corpus) | |
| 77 | 추가: .status() | |
| 78 | 추가: .unwrap() | |
| 79 | 추가: .success() | |
| 80 | 추가: ); | |
| 81 | 추가: let mut report = String::from("case\tlist\textract\n"); | |
| 82 | 추가: let mut failures = Vec::new(); | |
| 83 | 추가: let manifest = fs::read_to_string(corpus.join("cases.tsv")).unwrap(); | |
| 84 | 추가: let mut count = 0; | |
| 85 | 추가: for line in manifest.lines() { | |
| 86 | 추가: let columns: Vec<_> = line.split('\t').collect(); | |
| 87 | 추가: assert_eq!(columns.len(), 3); | |
| 88 | 추가: let (id, name, hex) = (columns[0], columns[1], columns[2]); | |
| 89 | 추가: let expected: Vec<_> = (0..hex.len()) | |
| 90 | 추가: .step_by(2) | |
| 91 | 추가: .map(|i| u8::from_str_radix(&hex[i..i + 2], 16).unwrap()) | |
| 92 | 추가: .collect(); | |
| 93 | 추가: let archive = NativePath::from_path(&corpus.join(format!("{id}.zip"))); | |
| 94 | 추가: let listed = execute(Action::List { | |
| 95 | 추가: archive: archive.clone(), | |
| 96 | 추가: }); | |
| 97 | 추가: let list_id = listed.iter().find_map(|event| match event { | |
| 98 | 추가: Message::ListEnd { | |
| 99 | 추가: entry_count: 1, | |
| 100 | 추가: list_id, | |
| 101 | 추가: } => Some(list_id.clone()), | |
| 102 | 추가: _ => None, | |
| 103 | 추가: }); | |
| 104 | 추가: let entries: Vec<_> = listed | |
| 105 | 추가: .iter() | |
| 106 | 추가: .filter_map(|event| match event { | |
| 107 | 추가: Message::Entry(entry) => Some(entry), | |
| 108 | 추가: _ => None, | |
| 109 | 추가: }) | |
| 110 | 추가: .collect(); | |
| 111 | 추가: let list_ok = terminal(&listed).outcome == Outcome::Completed | |
| 112 | 추가: && terminal(&listed).error == ErrorCode::None | |
| 113 | 추가: && list_id.is_some() | |
| 114 | 추가: && entries.len() == 1 | |
| 115 | 추가: && entries[0].name == name | |
| 116 | 추가: && entries[0].size == expected.len() as u64; | |
| 117 | 추가: let destination = scratch.join(id); | |
| 118 | 추가: directory(&destination); | |
| 119 | 추가: let extracted = execute(Action::Extract { | |
| 120 | 추가: archive, | |
| 121 | 추가: destination: NativePath::from_path(&destination), | |
| 122 | 추가: selection: Selection::All, | |
| 123 | 추가: list_id, | |
| 124 | 추가: gzip_output_name: None, | |
| 125 | 추가: }); | |
| 126 | 추가: let end = terminal(&extracted); | |
| 127 | 추가: let extract_ok = end.outcome == Outcome::Completed | |
| 128 | 추가: && end.error == ErrorCode::None | |
| 129 | 추가: && end.publication == Publication::Complete | |
| 130 | 추가: && end.cleanup == Cleanup::Complete | |
| 131 | 추가: && end.created_count == 1 | |
| 132 | 추가: && end.retained_partial_count == 0 | |
| 133 | 추가: && fs::read(destination.join(name)).ok().as_deref() == Some(expected.as_slice()) | |
| 134 | 추가: && fs::read_dir(&destination).unwrap().count() == 1; | |
| 135 | 추가: report.push_str(&format!( | |
| 136 | 추가: "{id}\t{}:{:?}\t{}:{:?}\n", | |
| 137 | 추가: if list_ok { "PASS" } else { "FAIL" }, | |
| 138 | 추가: terminal(&listed).error, | |
| 139 | 추가: if extract_ok { "PASS" } else { "FAIL" }, | |
| 140 | 추가: end.error | |
| 141 | 추가: )); | |
| 142 | 추가: if !list_ok || !extract_ok { | |
| 143 | 추가: failures.push(id.to_owned()); | |
| 144 | 추가: } | |
| 145 | 추가: count += 1; | |
| 146 | 추가: } | |
| 147 | 추가: assert_eq!(count, 1066); | |
| 148 | 추가: fs::write(scratch.join("results.tsv"), report).unwrap(); | |
| 149 | 추가: println!( | |
| 150 | 추가: "ZIP64 corpus: {count} cases, {} failed; {}", | |
| 151 | 추가: failures.len(), | |
| 152 | 추가: scratch.display() | |
| 153 | 추가: ); | |
| 154 | 추가: assert!( | |
| 155 | 추가: failures.is_empty(), | |
| 156 | 추가: "실패 {}개, 앞 12개: {:?}; 전체 결과: {}", | |
| 157 | 추가: failures.len(), | |
| 158 | 추가: &failures[..failures.len().min(12)], | |
| 159 | 추가: scratch.join("results.tsv").display() | |
| 160 | 추가: ); | |
| 161 | 추가: } |
| @@ -0,0 +1,175 @@ | ||
| 1 | 추가: """세 도구의 ZIP64 원본과 단일 볼륨 확장 필드 조합을 생성함.""" | |
| 2 | 추가: import ctypes as c | |
| 3 | 추가: import importlib.util | |
| 4 | 추가: import io | |
| 5 | 추가: import json | |
| 6 | 추가: from pathlib import Path | |
| 7 | 추가: import struct | |
| 8 | 추가: import subprocess | |
| 9 | 추가: import sys | |
| 10 | 추가: import zipfile | |
| 11 | 추가: | |
| 12 | 추가: NAME = "payload.bin" | |
| 13 | 추가: PAYLOAD = b"ZIP64 corpus payload\n" | |
| 14 | 추가: | |
| 15 | 추가: | |
| 16 | 추가: def module(name, path): | |
| 17 | 추가: spec = importlib.util.spec_from_file_location(name, path) | |
| 18 | 추가: result = importlib.util.module_from_spec(spec) | |
| 19 | 추가: spec.loader.exec_module(result) | |
| 20 | 추가: return result | |
| 21 | 추가: | |
| 22 | 추가: | |
| 23 | 추가: def python_zip(force=False, pipe=False): | |
| 24 | 추가: class Pipe(io.BytesIO): | |
| 25 | 추가: def seek(self, *args): | |
| 26 | 추가: raise io.UnsupportedOperation() | |
| 27 | 추가: | |
| 28 | 추가: output = Pipe() if pipe else io.BytesIO() | |
| 29 | 추가: with zipfile.ZipFile(output, "w", compression=zipfile.ZIP_STORED) as archive: | |
| 30 | 추가: with archive.open(NAME, "w", force_zip64=force) as target: | |
| 31 | 추가: target.write(PAYLOAD) | |
| 32 | 추가: return output.getvalue() | |
| 33 | 추가: | |
| 34 | 추가: | |
| 35 | 추가: def libarchive_zip(): | |
| 36 | 추가: reference = module( | |
| 37 | 추가: "archive_reference", | |
| 38 | 추가: Path(__file__).resolve().parents[1] / "rust-archive-worker/seven_zip_reference.py", | |
| 39 | 추가: ) | |
| 40 | 추가: lib = reference.library() | |
| 41 | 추가: lib.archive_write_set_format_zip.argtypes = [c.c_void_p] | |
| 42 | 추가: lib.archive_write_set_format_zip.restype = c.c_int | |
| 43 | 추가: lib.archive_version_string.restype = c.c_char_p | |
| 44 | 추가: archive = lib.archive_write_new() | |
| 45 | 추가: buffer = c.create_string_buffer(65536) | |
| 46 | 추가: used = c.c_size_t() | |
| 47 | 추가: entry = lib.archive_entry_new() | |
| 48 | 추가: | |
| 49 | 추가: def check(value): | |
| 50 | 추가: assert value == 0, lib.archive_error_string(archive) | |
| 51 | 추가: | |
| 52 | 추가: try: | |
| 53 | 추가: check(lib.archive_write_set_format_zip(archive)) | |
| 54 | 추가: check(lib.archive_write_set_format_option(archive, b"zip", b"zip64", b"1")) | |
| 55 | 추가: check(lib.archive_write_set_format_option(archive, b"zip", b"compression", b"store")) | |
| 56 | 추가: check(lib.archive_write_open_memory(archive, buffer, len(buffer), c.byref(used))) | |
| 57 | 추가: lib.archive_entry_set_pathname(entry, NAME.encode()) | |
| 58 | 추가: lib.archive_entry_set_filetype(entry, 0o100000) | |
| 59 | 추가: lib.archive_entry_set_perm(entry, 0o600) | |
| 60 | 추가: lib.archive_entry_set_size(entry, len(PAYLOAD)) | |
| 61 | 추가: lib.archive_entry_set_mtime(entry, 0, 0) | |
| 62 | 추가: check(lib.archive_write_header(archive, entry)) | |
| 63 | 추가: assert lib.archive_write_data(archive, PAYLOAD, len(PAYLOAD)) == len(PAYLOAD) | |
| 64 | 추가: check(lib.archive_write_close(archive)) | |
| 65 | 추가: return buffer.raw[:used.value], lib.archive_version_string().decode() | |
| 66 | 추가: finally: | |
| 67 | 추가: lib.archive_entry_free(entry) | |
| 68 | 추가: lib.archive_write_free(archive) | |
| 69 | 추가: | |
| 70 | 추가: | |
| 71 | 추가: def variant(original, central_mask, end_mask, local64=False): | |
| 72 | 추가: # 중앙 확장 필드는 원래 크기, 압축 크기, 오프셋, 디스크 순서임. | |
| 73 | 추가: end = bytearray(original[-22:]) | |
| 74 | 추가: central_at = struct.unpack_from("<I", end, 16)[0] | |
| 75 | 추가: body = bytearray(original[:central_at]) | |
| 76 | 추가: central = bytearray(original[central_at:-22]) | |
| 77 | 추가: assert struct.unpack_from("<H", central, 30)[0] == 0 | |
| 78 | 추가: assert struct.unpack_from("<H", central, 32)[0] == 0 | |
| 79 | 추가: if local64: | |
| 80 | 추가: name_len = struct.unpack_from("<H", body, 26)[0] | |
| 81 | 추가: packed, size = struct.unpack_from("<II", body, 18) | |
| 82 | 추가: struct.pack_into("<II", body, 18, 0xffffffff, 0xffffffff) | |
| 83 | 추가: struct.pack_into("<H", body, 28, 20) | |
| 84 | 추가: body[30 + name_len:30 + name_len] = struct.pack("<HHQQ", 1, 16, size, packed) | |
| 85 | 추가: struct.pack_into("<H", body, 4, 45) | |
| 86 | 추가: struct.pack_into("<H", central, 6, 45) | |
| 87 | 추가: extra = bytearray() | |
| 88 | 추가: for bit, offset, field_type in [(0, 24, "I"), (1, 20, "I"), (2, 42, "I"), (3, 34, "H")]: | |
| 89 | 추가: if central_mask & (1 << bit): | |
| 90 | 추가: value = struct.unpack_from("<" + field_type, central, offset)[0] | |
| 91 | 추가: struct.pack_into("<" + field_type, central, offset, 0xffff if bit == 3 else 0xffffffff) | |
| 92 | 추가: extra += struct.pack("<I" if bit == 3 else "<Q", value) | |
| 93 | 추가: if extra: | |
| 94 | 추가: central += struct.pack("<HH", 1, len(extra)) + extra | |
| 95 | 추가: struct.pack_into("<H", central, 30, len(extra) + 4) | |
| 96 | 추가: central_at = len(body) | |
| 97 | 추가: directory = body + central | |
| 98 | 추가: record = struct.pack( | |
| 99 | 추가: "<4sQHHIIQQQQ", b"PK\x06\x06", 44, 45, 45, 0, 0, 1, 1, len(central), central_at | |
| 100 | 추가: ) | |
| 101 | 추가: locator = struct.pack("<4sIQI", b"PK\x06\x07", 0, len(directory), 1) | |
| 102 | 추가: struct.pack_into("<II", end, 12, len(central), central_at) | |
| 103 | 추가: # EOCD의 디스크 두 필드, 항목 수 두 필드, 크기와 오프셋을 독립 확장함. | |
| 104 | 추가: for bit, offset, field_type in [(0, 4, "H"), (1, 6, "H"), (2, 8, "H"), | |
| 105 | 추가: (3, 10, "H"), (4, 12, "I"), (5, 16, "I")]: | |
| 106 | 추가: if end_mask & (1 << bit): | |
| 107 | 추가: struct.pack_into("<" + field_type, end, offset, 0xffff if field_type == "H" else 0xffffffff) | |
| 108 | 추가: return bytes(directory + record + locator + end) | |
| 109 | 추가: | |
| 110 | 추가: | |
| 111 | 추가: def generate(root): | |
| 112 | 추가: root = Path(root) | |
| 113 | 추가: root.mkdir(mode=0o700, parents=True, exist_ok=False) | |
| 114 | 추가: cases = [] | |
| 115 | 추가: | |
| 116 | 추가: def add(identifier, data, producer, payload=PAYLOAD): | |
| 117 | 추가: path = root / (identifier + ".zip") | |
| 118 | 추가: path.write_bytes(data) | |
| 119 | 추가: with zipfile.ZipFile(path) as reference: | |
| 120 | 추가: names = reference.namelist() | |
| 121 | 추가: assert len(names) == 1 | |
| 122 | 추가: assert reference.read(names[0]) == payload, identifier | |
| 123 | 추가: assert reference.testzip() is None, identifier | |
| 124 | 추가: cases.append((identifier, names[0], payload.hex(), producer)) | |
| 125 | 추가: | |
| 126 | 추가: original = python_zip() | |
| 127 | 추가: add("python-classic", original, "Python zipfile") | |
| 128 | 추가: add("python-force-local", python_zip(True), "Python zipfile force_zip64") | |
| 129 | 추가: add("python-force-descriptor", python_zip(True, True), "Python zipfile force_zip64 unseekable") | |
| 130 | 추가: native, version = libarchive_zip() | |
| 131 | 추가: assert b"PK\x06\x07" in native | |
| 132 | 추가: add("libarchive-force", native, version + " zip64=1") | |
| 133 | 추가: (root / NAME).write_bytes(PAYLOAD) | |
| 134 | 추가: subprocess.run( | |
| 135 | 추가: ["zip", "-q", "-fz", "infozip-native.zip", NAME], | |
| 136 | 추가: cwd=root, capture_output=True, check=True, | |
| 137 | 추가: ) | |
| 138 | 추가: info = (root / "infozip-native.zip").read_bytes() | |
| 139 | 추가: assert struct.unpack_from("<II", info, 18) == (0xffffffff, 0xffffffff) | |
| 140 | 추가: assert b"PK\x06\x07" in info | |
| 141 | 추가: add("infozip-force", info, "Info-ZIP -fz regular file") | |
| 142 | 추가: for central in range(16): | |
| 143 | 추가: for end in range(64): | |
| 144 | 추가: add(f"fields-c{central:02x}-e{end:02x}", variant(original, central, end), | |
| 145 | 추가: "Python zipfile + APPNOTE field substitution") | |
| 146 | 추가: add(f"local64-c{central:02x}", variant(original, central, 0, True), | |
| 147 | 추가: "Python zipfile + local size pair + central field substitution") | |
| 148 | 추가: expanded = variant(original, central, 0) | |
| 149 | 추가: add(f"central-only-c{central:02x}", expanded[:-98] + expanded[-22:], | |
| 150 | 추가: "Python zipfile + central fields without ZIP64 end records") | |
| 151 | 추가: previous = module( | |
| 152 | 추가: "previous_zip64", | |
| 153 | 추가: Path(__file__).resolve().parents[1] / "rust-archive-worker/hardening_cases.py", | |
| 154 | 추가: ) | |
| 155 | 추가: for kind in ["locator64", "offset64-descriptor", "offset64-descriptor-unsigned"]: | |
| 156 | 추가: directory = root / kind | |
| 157 | 추가: directory.mkdir() | |
| 158 | 추가: previous.generate(directory, kind, 20) | |
| 159 | 추가: add("previous-" + kind, (directory / "input").read_bytes(), "PR74 regression", bytes(20)) | |
| 160 | 추가: add("previous-eocd-disk", variant(original, 0, 3), "EOCD disk sentinel regression") | |
| 161 | 추가: add("previous-central-disk", variant(original, 8, 0), "central disk sentinel regression") | |
| 162 | 추가: (root / "cases.tsv").write_text( | |
| 163 | 추가: "".join("\t".join(row[:3]) + "\n" for row in cases), encoding="utf-8" | |
| 164 | 추가: ) | |
| 165 | 추가: (root / "provenance.json").write_text(json.dumps({ | |
| 166 | 추가: "python": sys.version, | |
| 167 | 추가: "libarchive": version, | |
| 168 | 추가: "infozip": subprocess.check_output(["zip", "-v"], text=True).splitlines()[:3], | |
| 169 | 추가: "cases": [{"id": row[0], "producer": row[3]} for row in cases], | |
| 170 | 추가: }, indent=4) + "\n", encoding="utf-8") | |
| 171 | 추가: print(f"Python reference CRC/content: {len(cases)} passed") | |
| 172 | 추가: | |
| 173 | 추가: | |
| 174 | 추가: if __name__ == "__main__": | |
| 175 | 추가: generate(sys.argv[1]) |
| @@ -0,0 +1,5 @@ | ||
| 1 | 추가: fn main() { | |
| 2 | 추가: if zipelo_archive_worker::runtime::serve(std::io::stdin(), std::io::stdout()).is_err() { | |
| 3 | 추가: std::process::exit(2); | |
| 4 | 추가: } | |
| 5 | 추가: } |