완전 복구용 로컬 헤더 손상 표본을 추가함
- 작성자
- 코노모리 카논
- 작성 시각
- 커밋
d525c7c23796b06048180c3b3d2bbaee8075989e- 부모
- 8e178e0
변경된 파일 5개
+124-6| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | # ZIP 복구 표본 |
| 2 | 2 | |
| 3 | 삭제: PLANS 8.10의 네 손상 종류를 자체 생성한 작은 ZIP으로 구분함. 정상 대조군 1개와 손상 표본 5개를 포함함. 실제 복구기 구현이나 제품 검증 결과가 아니라 복구 수용 시험용 입력과 기대값임. UI 변경 없음. | |
| 3 | 추가: PLANS 8.10의 네 손상 종류를 자체 생성한 작은 ZIP으로 구분함. 정상 대조군 1개와 손상 표본 6개를 포함함. 실제 복구기 구현이나 제품 검증 결과가 아니라 복구 수용 시험용 입력과 기대값임. UI 변경 없음. | |
| 4 | 4 | |
| 5 | 5 | ## 표본과 기대값 |
| 6 | 6 | |
| @@ -8,11 +8,12 @@ PLANS 8.10의 네 손상 종류를 자체 생성한 작은 ZIP으로 구분함. | ||
| 8 | 8 | |
| 9 | 9 | - `missing-directory.zip`: 중앙 디렉터리 시작부터 잘라낸 헤더 손상임. 로컬 헤더와 본문이 완전한 6개 항목을 원본 해시대로 복구해야 함. |
| 10 | 10 | - `broken-eocd.zip`: EOCD 서명 4바이트만 바꾼 헤더 손상임. 6개 항목을 원본 해시대로 복구해야 함. |
| 11 | 추가: - `broken-local-header.zip`: `한글/자료.txt`의 로컬 서명 4바이트만 바꾸고 중앙 목록, EOCD, 이름/extra 길이와 모든 본문을 유지함. 중앙 목록과 연속 로컬 범위가 1:1 대응하므로 CentralDirectory에서 6개 항목 전부를 해시대로 복구하고 known_entries=6, unknown_loss=false여야 함. 실제 게시와 마무리까지 성공하면 Completed/None, publication=Complete, created_count=1이 기대값임. 일반 판독기는 중앙 목록을 읽을 수 있어도 손상 항목의 내용을 읽을 때 실패해야 함. | |
| 11 | 12 | - `middle-truncated.zip`: 다섯 번째 항목 `middle.bin`의 본문 중간에서 잘라냄. 앞의 4개 항목만 복구하고 `middle.bin`을 정상 복구로 표시하면 안 됨. 뒤의 `after.txt`는 이름과 존재 자체를 손상본에서 관측할 수 없음. |
| 12 | 13 | - `body-corrupt.zip`: 중앙 디렉터리를 제거하고 `middle.bin` 본문의 1바이트를 뒤집음. CRC가 틀린 `middle.bin`을 제외한 5개 항목을 해시대로 복구해야 함. 뒤의 정상 `after.txt`까지 확인하여 손상 항목 이후의 탐색을 검증함. 중앙 디렉터리 제거는 일반 열기의 실패 후 복구 경로에 도달시키기 위한 별도 손상임. |
| 13 | 14 | - `unrecoverable.zip`: 첫 로컬 헤더의 20바이트만 남김. 검증 가능한 항목이 없으므로 복구본을 게시하거나 빈 ZIP 생성을 성공으로 표시하면 안 됨. |
| 14 | 15 | |
| 15 | 삭제: `oracle_states`는 원본을 알고 있는 시험의 판정임. `verified`만 복구본에 포함하고, `truncated`, `integrity_failed`, `not_observable`은 제외함. 이는 작업자 프로토콜의 enum 이름을 제안하는 것이 아님. 특히 중앙 목록이 없는 표본에서 앱이 사라진 항목의 이름이나 정확한 유실 개수를 알아낼 수 있다고 가정하지 않음. 복구된 파일들의 CRC와 해시가 일치해도 원본 전체의 완전성을 증명하지 못하므로 경고를 유지해야 함. | |
| 16 | 추가: `oracle_states`는 원본을 알고 있는 시험의 판정임. `verified`만 복구본에 포함하고, `truncated`, `integrity_failed`, `not_observable`은 제외함. 이는 작업자 프로토콜의 enum 이름을 제안하는 것이 아님. 특히 중앙 목록이 없는 표본에서 앱이 사라진 항목의 이름이나 정확한 유실 개수를 알아낼 수 있다고 가정하지 않음. LocalChain 표본은 복구된 파일들의 CRC와 해시가 일치해도 원본 전체의 완전성을 증명하지 못하므로 경고를 유지해야 함. `broken-local-header.zip`만 완전한 중앙 목록에 근거한 완전 복구 기대값을 가짐. warning_required=false는 유실/목록 불명 경고가 필수가 아니라는 뜻이며 헤더 재구성 안내나 원본 진위에 대한 설명을 금지하지 않음. | |
| 16 | 17 | |
| 17 | 18 | 모든 실행은 손상 입력을 그대로 두고 별도 경로에 복구본을 게시해야 함. 실행 전후 입력 SHA-256을 manifest의 값과 비교하고, 검증 실패 항목의 부분 출력이 게시되지 않았는지 검사해야 함. 경고, 종료 상태, 취소, 저장 실패, 링크와 경로 제한, 자원 제한은 이후 실제 작업자 통합 시험에서 별도로 확인해야 함. 이 묶음은 그 검증을 대신하지 않음. |
| 18 | 19 | |
| @@ -28,6 +29,8 @@ python3 -B -m unittest discover -s tests/ci -p test_zip_recovery_fixtures.py | ||
| 28 | 29 | |
| 29 | 30 | 기존 `tests/ci/run_rust.py local`의 Python 시험 탐색에도 연결함. 검증기는 정상본을 Python zipfile로 읽고 손상 연산, 고정 입력 해시, 각 로컬 항목의 CRC와 SHA-256, 불완전한 항목의 배제를 검사함. 로컬 항목 검사는 manifest의 알려진 위치를 사용하므로 범용 복구 알고리즘이나 손상 탐색 성공의 근거가 아님. 생성기는 고정 시간과 순서 및 Python 표준 라이브러리를 사용하며, `--check`는 현재 환경에서 커밋된 바이트의 재현성을 확인함. |
| 30 | 31 | |
| 32 | 추가: 완전 복구 표본은 zipfile이 읽은 중앙 목록으로 위치와 연속 범위를 확인한 뒤 메모리 사본의 로컬 서명 4바이트만 되돌려 원본과 바이트 단위로 비교함. 이 참조 재구성에서 6개 항목을 독립 판독하고 해시를 확인하며 디스크의 손상 입력은 수정하지 않음. 제품 복구기 실행과는 구분함. | |
| 33 | 추가: | |
| 31 | 34 | 실제 작업자가 복구본을 만든 뒤 아래처럼 항목 집합, 파일과 폴더 구분, 해시를 검사할 수 있음. 출력은 지정된 작업 폴더 안에 두어야 함. |
| 32 | 35 | |
| 33 | 36 | ```sh |
바이너리 파일이라 Diff를 표시하지 않아요.
파일 내려받기| @@ -283,6 +283,56 @@ | ||
| 283 | 283 | "after.txt": "not_observable" |
| 284 | 284 | } |
| 285 | 285 | } |
| 286 | 추가: }, | |
| 287 | 추가: { | |
| 288 | 추가: "file": "broken-local-header.zip", | |
| 289 | 추가: "category": "header_damage", | |
| 290 | 추가: "bytes": 1734, | |
| 291 | 추가: "sha256": "62f2b6a029a3654856feabbdc90882e124798ad50dbe54e0a54a2502fd464181", | |
| 292 | 추가: "mutations_from_control": [ | |
| 293 | 추가: { | |
| 294 | 추가: "operation": "replace", | |
| 295 | 추가: "offset": 65, | |
| 296 | 추가: "hex": "42414421" | |
| 297 | 추가: } | |
| 298 | 추가: ], | |
| 299 | 추가: "expected": { | |
| 300 | 추가: "publish_archive": true, | |
| 301 | 추가: "warning_required": false, | |
| 302 | 추가: "must_not_claim_complete_original": false, | |
| 303 | 추가: "must_preserve_source_sha256": "62f2b6a029a3654856feabbdc90882e124798ad50dbe54e0a54a2502fd464181", | |
| 304 | 추가: "verified_entries": [ | |
| 305 | 추가: "hello.txt", | |
| 306 | 추가: "한글/자료.txt", | |
| 307 | 추가: "empty.txt", | |
| 308 | 추가: "empty-dir/", | |
| 309 | 추가: "middle.bin", | |
| 310 | 추가: "after.txt" | |
| 311 | 추가: ], | |
| 312 | 추가: "excluded_entries": [], | |
| 313 | 추가: "oracle_states": { | |
| 314 | 추가: "hello.txt": "verified", | |
| 315 | 추가: "한글/자료.txt": "verified", | |
| 316 | 추가: "empty.txt": "verified", | |
| 317 | 추가: "empty-dir/": "verified", | |
| 318 | 추가: "middle.bin": "verified", | |
| 319 | 추가: "after.txt": "verified" | |
| 320 | 추가: }, | |
| 321 | 추가: "recovery_summary": { | |
| 322 | 추가: "mode": "CentralDirectory", | |
| 323 | 추가: "known_entries": 6, | |
| 324 | 추가: "verified_entries": 6, | |
| 325 | 추가: "lost_entries": 0, | |
| 326 | 추가: "unverified_entries": 0, | |
| 327 | 추가: "unknown_loss": false | |
| 328 | 추가: }, | |
| 329 | 추가: "terminal_after_successful_publication": { | |
| 330 | 추가: "outcome": "Completed", | |
| 331 | 추가: "error": "None", | |
| 332 | 추가: "publication": "Complete", | |
| 333 | 추가: "created_count": 1 | |
| 334 | 추가: } | |
| 335 | 추가: } | |
| 286 | 336 | } |
| 287 | 337 | ] |
| 288 | 338 | } |
| @@ -58,6 +58,9 @@ def corpus(): | ||
| 58 | 58 | corrupt[corrupt_offset] ^= 0x80 |
| 59 | 59 | bad_eocd = bytearray(original) |
| 60 | 60 | bad_eocd[-22:-18] = b"BAD!" |
| 61 | 추가: local_offset = entries[1]["local_offset"] | |
| 62 | 추가: bad_local = bytearray(original) | |
| 63 | 추가: bad_local[local_offset:local_offset + 4] = b"BAD!" | |
| 61 | 64 | cases = [ |
| 62 | 65 | ("control.zip", "control", original, [], ["verified"] * 6), |
| 63 | 66 | ("missing-directory.zip", "header_damage", original[:directory_offset], |
| @@ -74,6 +77,9 @@ def corpus(): | ||
| 74 | 77 | ["verified"] * 4 + ["integrity_failed", "verified"]), |
| 75 | 78 | ("unrecoverable.zip", "unrecoverable", original[:20], |
| 76 | 79 | [{"operation": "truncate", "offset": 20}], ["not_observable"] * 6), |
| 80 | 추가: ("broken-local-header.zip", "header_damage", bytes(bad_local), | |
| 81 | 추가: [{"operation": "replace", "offset": local_offset, "hex": "42414421"}], | |
| 82 | 추가: ["verified"] * 6), | |
| 77 | 83 | ] |
| 78 | 84 | files = {} |
| 79 | 85 | samples = [] |
| @@ -87,8 +93,8 @@ def corpus(): | ||
| 87 | 93 | "mutations_from_control": mutations, |
| 88 | 94 | "expected": { |
| 89 | 95 | "publish_archive": bool(verified) and category != "control", |
| 90 | 삭제: "warning_required": category != "control", | |
| 91 | 삭제: "must_not_claim_complete_original": category != "control", | |
| 96 | 추가: "warning_required": category != "control" and name != "broken-local-header.zip", | |
| 97 | 추가: "must_not_claim_complete_original": category != "control" and name != "broken-local-header.zip", | |
| 92 | 98 | "must_preserve_source_sha256": sha256(data), |
| 93 | 99 | "verified_entries": verified, |
| 94 | 100 | "excluded_entries": [entry["name"] for entry, state in zip(entries, states) |
| @@ -96,6 +102,21 @@ def corpus(): | ||
| 96 | 102 | "oracle_states": dict(zip((entry["name"] for entry in entries), states)), |
| 97 | 103 | }, |
| 98 | 104 | }) |
| 105 | 추가: if name == "broken-local-header.zip": | |
| 106 | 추가: samples[-1]["expected"]["recovery_summary"] = { | |
| 107 | 추가: "mode": "CentralDirectory", | |
| 108 | 추가: "known_entries": 6, | |
| 109 | 추가: "verified_entries": 6, | |
| 110 | 추가: "lost_entries": 0, | |
| 111 | 추가: "unverified_entries": 0, | |
| 112 | 추가: "unknown_loss": False, | |
| 113 | 추가: } | |
| 114 | 추가: samples[-1]["expected"]["terminal_after_successful_publication"] = { | |
| 115 | 추가: "outcome": "Completed", | |
| 116 | 추가: "error": "None", | |
| 117 | 추가: "publication": "Complete", | |
| 118 | 추가: "created_count": 1, | |
| 119 | 추가: } | |
| 99 | 120 | files[name] = data |
| 100 | 121 | manifest = { |
| 101 | 122 | "schema_version": 1, |
| @@ -20,6 +20,14 @@ def digest(data): | ||
| 20 | 20 | return hashlib.sha256(data).hexdigest() |
| 21 | 21 | |
| 22 | 22 | |
| 23 | 추가: def reference_restore_local_signature(data): | |
| 24 | 추가: with zipfile.ZipFile(io.BytesIO(data)) as archive: | |
| 25 | 추가: offset = archive.getinfo("한글/자료.txt").header_offset | |
| 26 | 추가: if data[offset:offset + 4] != b"BAD!": | |
| 27 | 추가: raise ValueError("표본의 로컬 서명 손상 위치 불일치") | |
| 28 | 추가: return data[:offset] + b"PK\x03\x04" + data[offset + 4:] | |
| 29 | 추가: | |
| 30 | 추가: | |
| 23 | 31 | def local_payload(data, entry): |
| 24 | 32 | offset = entry["local_offset"] |
| 25 | 33 | if data[offset:offset + 4] != b"PK\x03\x04" or len(data) < offset + 30: |
| @@ -115,11 +123,47 @@ class CorpusTests(unittest.TestCase): | ||
| 115 | 123 | if sample["category"] == "control": |
| 116 | 124 | continue |
| 117 | 125 | with self.subTest(name=name), self.assertRaises(zipfile.BadZipFile): |
| 118 | 삭제: zipfile.ZipFile(ROOT / name) | |
| 126 | 추가: with zipfile.ZipFile(ROOT / name) as archive: | |
| 127 | 추가: for info in archive.infolist(): | |
| 128 | 추가: archive.read(info) | |
| 129 | 추가: | |
| 130 | 추가: def test_complete_inventory_with_only_local_signature_damage(self): | |
| 131 | 추가: original = (ROOT / "control.zip").read_bytes() | |
| 132 | 추가: damaged = (ROOT / "broken-local-header.zip").read_bytes() | |
| 133 | 추가: with zipfile.ZipFile(io.BytesIO(damaged)) as archive: | |
| 134 | 추가: self.assertEqual(archive.namelist(), list(ENTRIES)) | |
| 135 | 추가: self.assertEqual(damaged[archive.start_dir:], original[archive.start_dir:]) | |
| 136 | 추가: offset = 0 | |
| 137 | 추가: for info in archive.infolist(): | |
| 138 | 추가: self.assertEqual(info.header_offset, offset) | |
| 139 | 추가: name_size, extra_size = struct.unpack_from("<HH", damaged, offset + 26) | |
| 140 | 추가: offset += 30 + name_size + extra_size + info.compress_size | |
| 141 | 추가: self.assertEqual(offset, archive.start_dir) | |
| 142 | 추가: with self.assertRaises(zipfile.BadZipFile): | |
| 143 | 추가: archive.read("한글/자료.txt") | |
| 144 | 추가: repaired = reference_restore_local_signature(damaged) | |
| 145 | 추가: self.assertEqual(repaired, original) | |
| 146 | 추가: with zipfile.ZipFile(io.BytesIO(repaired)) as archive: | |
| 147 | 추가: self.assertIsNone(archive.testzip()) | |
| 148 | 추가: for info in archive.infolist(): | |
| 149 | 추가: self.assertEqual(digest(archive.read(info)), ENTRIES[info.filename]["sha256"]) | |
| 150 | 추가: self.assertEqual((ROOT / "broken-local-header.zip").read_bytes(), damaged) | |
| 151 | 추가: expected = SAMPLES["broken-local-header.zip"]["expected"] | |
| 152 | 추가: self.assertEqual(expected["recovery_summary"], { | |
| 153 | 추가: "mode": "CentralDirectory", "known_entries": 6, "verified_entries": 6, | |
| 154 | 추가: "lost_entries": 0, "unverified_entries": 0, "unknown_loss": False, | |
| 155 | 추가: }) | |
| 156 | 추가: self.assertFalse(expected["must_not_claim_complete_original"]) | |
| 157 | 추가: self.assertFalse(expected["warning_required"]) | |
| 158 | 추가: self.assertEqual(expected["terminal_after_successful_publication"], { | |
| 159 | 추가: "outcome": "Completed", "error": "None", "publication": "Complete", "created_count": 1, | |
| 160 | 추가: }) | |
| 119 | 161 | |
| 120 | 162 | def test_verified_entries_have_intact_local_payloads(self): |
| 121 | 163 | for name, sample in SAMPLES.items(): |
| 122 | 164 | data = (ROOT / name).read_bytes() |
| 165 | 추가: if name == "broken-local-header.zip": | |
| 166 | 추가: data = reference_restore_local_signature(data) | |
| 123 | 167 | for entry_name in sample["expected"]["verified_entries"]: |
| 124 | 168 | with self.subTest(sample=name, entry=entry_name): |
| 125 | 169 | payload = local_payload(data, ENTRIES[entry_name]) |
| @@ -132,7 +176,7 @@ class CorpusTests(unittest.TestCase): | ||
| 132 | 176 | with self.subTest(sample=name, entry=entry_name), self.assertRaises(ValueError): |
| 133 | 177 | local_payload(data, ENTRIES[entry_name]) |
| 134 | 178 | counts = [len(sample["expected"]["verified_entries"]) for sample in SAMPLES.values()] |
| 135 | 삭제: self.assertEqual(counts, [6, 6, 6, 4, 5, 0]) | |
| 179 | 추가: self.assertEqual(counts, [6, 6, 6, 4, 5, 0, 6]) | |
| 136 | 180 | self.assertEqual(SAMPLES["middle-truncated.zip"]["expected"]["oracle_states"]["after.txt"], |
| 137 | 181 | "not_observable") |
| 138 | 182 |