승인한 작업의 메타데이터 예산을 확대한다
- 작성자
- 시로사키 하나
- 작성 시각
- 커밋
97d096da61848e3e9f09ae3b99f4910eec14850e- 부모
- 4e0ec55
변경된 파일 12개
+383-47| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | - ZIP32/ZIP64 Store/Deflate 목록과 해제, ZIP32/ZIP64 생성, 기본 TAR/USTAR, GZ, TAR.GZ, TAR.BZ2, TAR.XZ, 비암호화 7z 해제를 지원합니다. GZ 연결 멤버는 하나의 논리 스트림으로 합칩니다. 다중 볼륨, UTF-8로 해석할 수 없는 ZIP 이름, PAX/GNU 확장과 특수 항목 해제는 미지원입니다. |
| 6 | 6 | - ZIP 이름: UTF-8 플래그(비트 11)가 있으면 이름이 UTF-8이어야 하며 아니면 Integrity입니다. 플래그가 없으면 CRC가 원래 이름과 맞는 Info-ZIP Unicode Path 확장 필드(0x7075, 버전 1)를 우선 쓰고, 다음으로 UTF-8로 유효한 이름 바이트를 그대로 씁니다(Linux/macOS 도구의 기본 동작). CRC가 다르거나 버전이 다른 확장 필드는 무시합니다. 그 밖의 CP437/CP949 등 레거시 이름은 코드 페이지를 추측하지 않고 UnsupportedFeature로 거부합니다. 어느 경로로 얻은 이름이든 같은 경로 안전성 검사와 충돌 검사를 거칩니다. |
| 7 | 7 | - ZIP/TAR/GZ/TAR.GZ/7z 목록과 해제는 입력 기본 한도 u64::MAX, 해제 총량 16 GiB, 항목 10,000개입니다. 기존 Start와 StartInteractive의 limits는 이 값을 낮출 수 있습니다. 별도 StartGuarded의 승인 흐름은 아래 절을 따릅니다. 64 KiB 버퍼와 임시 파일로 입력과 검증 완료 payload를 처리해 모든 출력의 CRC, 크기와 경로를 게시 전에 검사합니다. checkpoint마다 취소, 부모 프로세스 생존과 300초 한도를 확인합니다. ZIP 생성은 원본을 하나씩 스냅샷으로 읽어 스트리밍으로 압축하며 원본 크기 합계에 16 GiB 한도를 적용합니다. ZIP64 크기와 오프셋은 필요한 항목에만 기록합니다. slice 기반 archive parser는 입력 64 MiB/출력 128 MiB, slice ZIP builder는 원본 및 결과 128 MiB 한도를 유지합니다. |
| 8 | 삭제: - 경로 깊이는 64개 구성 요소, 이름/출력 계획 메타데이터 예산은 8 MiB, 출력 계획 노드는 32,768개로 제한합니다. 이름 복제와 인덱스 비용을 보수적으로 계산해 할당 전에 Limit으로 거부합니다. | |
| 8 | 추가: - 경로 깊이는 64개 구성 요소이며 승인 전 이름/출력 계획 메타데이터 예산은 8 MiB, 출력 계획 노드는 32,768개로 제한합니다. 유효한 StartGuarded 자원 승인 후에만 각각 64 MiB와 262,144개로 확대합니다. 이름 복제와 인덱스 비용을 보수적으로 계산해 할당 전에 Limit으로 거부합니다. | |
| 9 | 9 | - GZip 내부 형식은 완전한 USTAR magic이 있을 때만 TAR로 판별합니다. magic이 없는 영값 데이터는 길이와 무관하게 raw GZip으로 유지하며 명시 출력명이 필요합니다. |
| 10 | 10 | - ListId는 열린 파일 객체, 전체 입력 SHA-256과 catalog version에 연결됩니다. 입력을 다시 읽어 검증한 전용 임시 파일 스냅샷만 해독합니다. 불일치는 출력 전 SourceChanged이며 목록을 다시 열어야 합니다. 원본의 사후 변경 감시나 파일 잠금 보장은 아닙니다. |
| 11 | 11 | - 출력 폴더는 미리 존재해야 합니다. Linux는 소유 UID가 같고 group/other 쓰기가 없는 폴더만 허용합니다. openat/O_NOFOLLOW로 디렉터리를 고정하고 새 임시 파일을 배타적으로 만든 뒤 hard link로 게시합니다. 기존 파일과 링크를 덮어쓰지 않습니다. Windows는 reparse point를 거부하고 부모 디렉터리 핸들에서 delete sharing을 제한합니다. |
| @@ -29,7 +29,7 @@ revision 2의 기존 필드와 오류 tag 0~12 및 입력/출력 기본 한도 | ||
| 29 | 29 | 비암호화 7z의 단일 입력/출력 coder인 Copy, LZMA와 LZMA2를 Rust 코드로 해독합니다. solid substream, 빈 파일/디렉터리, UTF-16LE 이름과 한 단계 압축 헤더를 처리합니다. 추가 라이브러리나 제품 외부 명령을 사용하지 않습니다. 형식 근거는 [7z 명세](https://www.7-zip.org/7z.html)와 [LZMA SDK 명세 안내](https://www.7-zip.org/sdk.html)입니다. |
| 30 | 30 | |
| 31 | 31 | - 시작 헤더/다음 헤더 CRC, packed/folder/substream CRC가 있을 때 해당 CRC와 크기, 스트림의 끝을 검증합니다. 경로, 충돌과 모든 선택 내용 검증이 끝난 뒤 기존 안전 게시 경로로 넘깁니다. 목록은 데이터 CRC 검증 성공을 뜻하지 않습니다. |
| 32 | 삭제: - 기본 입력 한도 u64::MAX, 해제 총량 16 GiB와 기존 항목/이름 한도를 적용합니다. 압축 해제된 헤더도 최대 8 MiB이고 헤더 중첩은 한 단계입니다. 사전은 최대 64 MiB, LZMA의 lc+lp는 최대 4입니다. 최근 8 MiB 사전만 메모리에 두고 더 먼 참조는 임시 파일에서 읽습니다. 먼 거리 참조가 많은 파일은 추가 디스크 I/O가 발생합니다. 해독 중 checkpoint에서 취소와 시간 한도를 확인합니다. | |
| 32 | 추가: - 기본 입력 한도 u64::MAX, 해제 총량 16 GiB와 기존 항목/이름 한도를 적용합니다. 압축 해제된 헤더는 승인 전 최대 8 MiB, 승인 후 최대 64 MiB이고 헤더 중첩은 한 단계입니다. 사전은 최대 64 MiB, LZMA의 lc+lp는 최대 4입니다. 최근 8 MiB 사전만 메모리에 두고 더 먼 참조는 임시 파일에서 읽습니다. 먼 거리 참조가 많은 파일은 추가 디스크 I/O가 발생합니다. 해독 중 checkpoint에서 취소와 시간 한도를 확인합니다. | |
| 33 | 33 | - 암호화 7z, 다중 coder 필터 체인(BCJ/BCJ2/Delta 등), PPMd/BZip2, 분할/SFX, external metadata, additional streams와 anti 항목은 미지원입니다. 링크, reparse point와 특수 Unix 항목은 거부합니다. 지원하지 않는 구조를 성공으로 처리하지 않습니다. |
| 34 | 34 | - solid 그룹의 압축 크기는 첫 substream에만 기록하고 나머지는 0으로 표시합니다. 각 파일의 정확한 비압축 크기는 유지합니다. |
| 35 | 35 | - 합성 표본은 Python 표준 lzma로 생성합니다. 별도로 시스템 libarchive가 만든 LZMA1/LZMA2 표본을 해제하고, 합성 표본도 libarchive 읽기 API로 검사합니다. libarchive는 Linux 시험의 독립 참조 도구이며 제품 의존성이 아닙니다. 시험 도구와 표본은 tests/rust-archive-worker 아래에 있습니다. |
| @@ -39,7 +39,7 @@ revision 2의 기존 필드와 오류 tag 0~12 및 입력/출력 기본 한도 | ||
| 39 | 39 | |
| 40 | 40 | TAR.BZ2와 TAR.XZ는 확장자가 아닌 BZh 및 XZ 매직으로 판별하고 비공개 임시 파일로 먼저 해제합니다. 연결된 BZip2/XZ 스트림은 하나의 TAR로 합치며 XZ의 4바이트 정렬 스트림 패딩도 허용합니다. 빈 TAR, USTAR 이름과 빈 폴더를 지원하지만 독립 BZ2/XZ 데이터 파일은 TAR가 아니면 거부합니다. |
| 41 | 41 | |
| 42 | 삭제: 해제 총량은 TAR 헤더와 패딩을 포함해 기존 16 GiB 이하이며 요청으로 낮출 수 있습니다. 64 KiB씩 실제 해제량을 확인하고 기록 전에 임시 저장소의 공간을 검사합니다. XZ는 블록별 LZMA2 디코더 메모리 32 MiB, 인덱스 8 MiB, 스트림 수와 스트림당 블록 수 각각 32,768을 상한으로 둡니다. 이 상한을 넘는 정상 파일도 Limit로 거부합니다. 해제 전체와 TAR 경로, 항목 종류 및 이름 충돌을 검증하기 전에는 목적지에 게시하지 않습니다. 출력 공간 검사, 안전한 충돌 처리, 취소와 300초 시간 제한도 기존 흐름을 사용합니다. | |
| 42 | 추가: 해제 총량은 TAR 헤더와 패딩을 포함해 기존 16 GiB 이하이며 요청으로 낮출 수 있습니다. 64 KiB씩 실제 해제량을 확인하고 기록 전에 임시 저장소의 공간을 검사합니다. XZ는 블록별 LZMA2 디코더 메모리 32 MiB, 인덱스는 승인 전 8 MiB, 승인 후 64 MiB이며 스트림 수와 스트림당 블록 수는 각각 승인 전 32,768개, 승인 후 262,144개를 상한으로 둡니다. 이 상한을 넘는 정상 파일도 Limit로 거부합니다. 해제 전체와 TAR 경로, 항목 종류 및 이름 충돌을 검증하기 전에는 목적지에 게시하지 않습니다. 출력 공간 검사, 안전한 충돌 처리, 취소와 300초 시간 제한도 기존 흐름을 사용합니다. | |
| 43 | 43 | |
| 44 | 44 | XZ의 헤더, 인덱스, 푸터 CRC와 역방향 크기 및 전체 선언 해제량을 확인하고 실제 해제량과 비교합니다. 각 블록의 헤더와 LZMA2 청크 경계를 따라 압축 길이와 해제량을 인덱스 레코드 및 선택적 헤더 크기와 대조하므로 다른 블록이나 연결 스트림의 크기 변조가 상쇄되어도 Integrity로 거부합니다. 지원하는 BCJ와 Delta 필터는 길이를 보존합니다. 이 사전 검사는 payload를 해제하거나 할당하지 않으며 기존 디코더가 청크 내용과 데이터 블록의 CRC32/CRC64/SHA256 검사를 수행한 뒤에만 게시합니다. [XZ 명세 4.3절](https://tukaani.org/xz/xz-file-format.txt)의 블록별 Unpadded Size와 Uncompressed Size 검사를 적용합니다. XZ의 Check=None도 형식대로 허용하므로 데이터 체크섬이 없는 파일의 내용 무결성을 보장하지 않습니다. TAR의 PAX/GNU 확장, 링크와 특수 항목의 기존 제한도 유지합니다. |
| 45 | 45 | |
| @@ -113,9 +113,11 @@ Python 표준 bz2, lzma와 tarfile로 독립 생성 및 해제한 결과의 SHA2 | ||
| 113 | 113 | - 승인 후에도 64 GiB와 200,000개 정책 상한, 메타데이터와 사전 예산, 경로 및 무결성, 임시 저장소와 목적지 공간 검사를 적용합니다. ZIP 생성은 원본 논리 크기 합계를 제한하며 ZIP 구조와 암호화로 늘어나는 저장 공간을 별도로 계산합니다. 이미 게시한 출력은 실패나 취소 시 유지하고 게시 및 정리 상태를 보고합니다. |
| 114 | 114 | - 승인된 작업은 전체 300초 대신 진행이 60초 동안 없을 때 Limit로 중단합니다. 실제 읽기, 해독, 쓰기와 메타데이터 수집만 진행으로 계산하며 반복 check 호출은 기한을 늘리지 않습니다. 암호, 충돌과 자원 질문은 한 번에 하나이며 각 응답 대기는 300초입니다. 유효한 응답 뒤에는 사용자 대기 시간을 제외하고 정체 감시를 재개합니다. 기존 요청의 전체 300초 제한은 유지합니다. OS의 블로킹 I/O를 강제로 중단하는 보장은 아닙니다. |
| 115 | 115 | |
| 116 | 삭제: 현재 남은 제약: 기존 8 MiB 메타데이터 예산과 32,768개 노드 상한을 유지하므로 실제 항목 200,000개까지 처리할 수 있다는 뜻은 아닙니다. 소스 경로도 이 예산을 사용합니다. 메타데이터 저장 방식과 예산 결정, 정확한 codec 인계 검토 및 화면 연동 전까지 초안을 유지합니다. | |
| 116 | 추가: 메타데이터 정책은 유효한 자원 승인 여부로 선택하며 요청의 ceiling만 늘려서는 확대되지 않습니다. 원본 계획의 경로와 대기 이름은 확대 작업에서 같은 항목의 복사 비용으로 계산하고 노드를 중복 가산하지 않습니다. 이름 및 원본 경로의 바이트 비용과 암묵적 상위 폴더 노드는 계속 계산하므로 긴 경로나 많은 상위 폴더가 있으면 항목 200,000개 이전에도 Limit로 중단될 수 있습니다. 승인 전과 기존 slice API의 메타데이터 한도 및 계산 방식은 유지합니다. 기존 대용량 회귀의 64 MiB RSS 목표는 기본 메타데이터 정책의 측정값이며 확대 작업 전체의 메모리 상한을 뜻하지 않습니다. | |
| 117 | 117 | |
| 118 | 삭제: 시험은 실제 64 GiB를 쓰지 않고 수치 경계와 축소한 limits/ceiling을 사용합니다. `resource_budget.rs`는 16 GiB 아래/경계/초과, 64 GiB 초과, 10,000개 및 200,000개 경계, 압축률 경계와 가상 시계의 60초 정체를 검사합니다. `guarded.rs`는 실제 작업자 승인/거부, 오래된 응답, 암호/충돌 순서, 승인 뒤 공간 실패, 여러 형식과 작은 고압축 입력의 경고 및 취소를 검사합니다. | |
| 118 | 추가: 작업자는 짧은 이름의 빈 ZIP 항목 200,000개 목록을 승인 후 처리하는 시험을 통과해야 합니다. 앱 활성화와 UI 상황, 시험, 가이드는 frontend 연동 범위이며 완료 전까지 초안을 유지합니다. | |
| 119 | 추가: | |
| 120 | 추가: 시험은 실제 64 GiB를 쓰지 않고 수치 경계와 축소한 limits/ceiling을 사용합니다. `resource_budget.rs`는 16 GiB 아래/경계/초과, 64 GiB 초과, 10,000개 및 200,000개 경계, 압축률 경계와 가상 시계의 60초 정체를 검사합니다. `metadata_policy.rs`는 축소한 바이트와 노드 예산, 원본 계획과 암묵적 폴더 계산을 확인합니다. `guarded.rs`는 승인 전 메타데이터 거부, 승인 뒤 200,000개 목록, 실제 작업자 승인/거부, 오래된 응답, 암호/충돌 순서, 승인 뒤 공간 실패, 여러 형식과 작은 고압축 입력의 경고 및 취소를 검사합니다. | |
| 119 | 121 | |
| 120 | 122 | ## 검증과 의존성 |
| 121 | 123 |
| @@ -165,13 +165,13 @@ | ||
| 165 | 165 | "gzip_ratio": "No compression-ratio rejection, including concatenated members. Aggregate decoded bytes, including TAR headers/padding, cannot exceed output quota.", |
| 166 | 166 | "tar_ratio": "Plain TAR copies declared nonoverlapping ranges within the captured input. The sum of file sizes cannot exceed output quota.", |
| 167 | 167 | "arithmetic": "Checked u64 offsets and totals; free-space block-to-byte conversion uses u128 to avoid multiplication overflow.", |
| 168 | 삭제: "memory_target": "ZIP/TAR/GZ/TAR.GZ/7z List/Extract and ZIP creation: worker process peak RSS <=64 MiB in Linux regression with independently generated 1 GiB payloads. This is a measured target, not an OS-enforced RSS cap. Metadata budget remains 8 MiB.", | |
| 168 | 추가: "memory_target": "ZIP/TAR/GZ/TAR.GZ/7z List/Extract and ZIP creation: worker process peak RSS <=64 MiB in Linux regression with independently generated 1 GiB payloads. This is a measured target, not an OS-enforced RSS cap. The 64 MiB RSS regression target uses the default 8 MiB metadata policy; approved expanded metadata jobs may use more RSS.", | |
| 169 | 169 | "staging": "64 KiB buffers; immutable input capture and verified decoded content use private temporary files that are removed on last-handle close. No decoded content is published until the entire catalog and integrity checks succeed. Temporary disk usage can include the archive plus expanded content plus current destination temporary file; disk exhaustion fails with DiskFull and closes/removes unpublished data.", |
| 170 | 170 | "legacy": "The slice parser keeps 64 MiB input /128 MiB output caps; the slice ZIP builder keeps 128 MiB source/result caps. Runtime 7z and ZIP creation use streaming file paths.", |
| 171 | 171 | "parent_lifetime": "Capture native parent before reading Start. At decode/read/write/password checkpoints, fail Io if parent is gone; close anonymous staging and remove current unpublished destination temp. stdin EOF alone remains valid for one-shot requests. Already published entries and directories are reported and retained. A blocked OS file operation cannot be forcibly interrupted by this cooperative guard.", |
| 172 | 172 | "disk_space": "Advisory free-space checks use opened Linux x86_64 filesystem handles (fstatvfs) or the Windows handle-derived directory (GetDiskFreeSpaceExW). Legacy Start groups remaining staging and selected output logical bytes by volume before ZIP/7z decoding and before publication. StartInteractive checks required staging before choices, then checks only the current non-skipped output at its resolved name immediately before publication; do not charge undecided or skipped files to the destination. For GZip with unknown expanded size, check staging space before each decoded chunk, then preflight selected output. Input capture also checks its snapshot space. Insufficient space returns DiskFull tag 13. Query failure and other I/O errors retain Io tag 8. Checks do not reserve space or account for every metadata/block-allocation overhead; later ENOSPC still closes staging and removes current unpublished output.", |
| 173 | 173 | "remaining_risk": "High compression ratios within 16 GiB may expand fully onto disk. Resource duration, cooperative cancellation and measured memory target remain. Free-space checks can race with other disk users; already published outputs are retained on failure.", |
| 174 | 삭제: "seven_zip": "Copy, LZMA and LZMA2 use file-backed solid output with checked declared/actual output totals. Encoded headers remain limited to 8 MiB. Dictionary size remains at most 64 MiB; only the last 8 MiB is cached in memory and older dictionary bytes are read from the temporary output.", | |
| 174 | 추가: "seven_zip": "Copy, LZMA and LZMA2 use file-backed solid output with checked declared/actual output totals. Encoded headers are limited to the active metadata policy: 8 MiB before a valid resource grant, 64 MiB after it. Dictionary size remains at most 64 MiB; only the last 8 MiB is cached in memory and older dictionary bytes are read from the temporary output.", | |
| 175 | 175 | "create_zip": "The sum of source logical bytes cannot exceed min(input,output) quotas. output defaults to 16 GiB of uncompressed source content; ZIP container/encryption overhead may exceed that logical content quota. Capture one immutable source at a time, stream Store/Deflate and optional AES-256 through 64 KiB buffers, then publish the completed ZIP without replacing existing files. Emit ZIP64 sizes/offsets only when their 32-bit fields would overflow or equal the sentinel. Check staging and destination free space; StorageFull maps to DiskFull tag 13 and other I/O failures retain Io tag 8." |
| 176 | 176 | }, |
| 177 | 177 | "validation": "Implementation results belong in the PR verification record. No OS sandbox or native Windows execution claim.", |
| @@ -202,7 +202,7 @@ | ||
| 202 | 202 | "agreement": "Proposed semantic extension under manager task 82093f56-73b7-4be4-ba6d-2597ffc2c6f7; frontend joint agreement is pending. Revision 2 fields, encoding, numeric quotas and error tags are unchanged.", |
| 203 | 203 | "roots": "Each source may be a regular file or directory. archive_name names that root inside the ZIP; directory descendants retain relative paths and every directory, including empty directories, gets a trailing-slash ZIP entry.", |
| 204 | 204 | "links": "Reject the whole job with UnsafePath for symbolic links, Windows reparse points, special files or unsafe/non-UTF-8 descendant names. Do not skip entries or follow external links. Open each path component without following links; enumerate pinned directories.", |
| 205 | 삭제: "limits": "All expanded file and directory entries count toward entries (default 10000). Only file logical bytes count toward min(input,output), default output 16 GiB. Preserve 8 MiB metadata and 64-component name limits. Validate the complete plan and case-insensitive/path-prefix conflicts before requesting a password.", | |
| 205 | 추가: "limits": "All expanded file and directory entries count toward entries (default 10000). Only file logical bytes count toward min(input,output), default output 16 GiB. Keep 64-component names and the active metadata budget. Legacy/unapproved plans retain 8 MiB and 32768 nodes; resource-approved plans use 64 MiB and 262144 nodes. In approved source plans, path and pending-name copies consume bytes but share their entry node. Validate the complete plan and case-insensitive/path-prefix conflicts before requesting a password.", | |
| 206 | 206 | "consistency": "Capture each file from its validated open handle. Compare planned object identity, kind, size and modification time before capture and check planned objects again before publishing the completed ZIP; detected changes fail SourceChanged. This is not an atomic snapshot of an entire directory tree.", |
| 207 | 207 | "encryption": "AES-256 protects file contents using the existing AE-2 encoding. Directory entries are stored as zero-byte unencrypted directory records; entry names remain visible, as with other ZIP entries." |
| 208 | 208 | }, |
| @@ -227,16 +227,16 @@ | ||
| 227 | 227 | "disk_space": "Required input capture and complete integrity staging checks remain before conflict questions. Defer destination space checks until the current choice is resolved. Skip has no destination byte charge; overwrite, rename and non-conflicting files are checked immediately before their publication. Preserve legacy Start aggregate preflight, limits, per-write checks and partial-output reporting." |
| 228 | 228 | }, |
| 229 | 229 | "guarded_resources": { |
| 230 | 삭제: "status": "worker-implemented; frontend activation and exact wire handoff review pending", | |
| 230 | 추가: "status": "worker-implemented; wire handoff confirmed, frontend activation pending", | |
| 231 | 231 | "agreement": "Frontend flow agreement 6fe5a494-7d5a-4bda-a7d3-831fb43e9238 and manager policy b3a743d2-10de-495c-8fdb-ecf2a5f3b453. Frame version 1, revision 3 messages and enum tags remain unchanged; this is an explicit opt-in extension.", |
| 232 | 232 | "admission": "After Accepted, request the output and/or entries scopes that ceiling increases above Start limits before capturing input or planning sources. Usage estimates and actuals are unknown at this point; report current staging-volume free space. The caller must show the requested ceilings and unknown values, not invent estimates. An earlier confirmation is needed because input capture itself can exceed 300 seconds. Each granted scope is confined to this job.", |
| 233 | 삭제: "ratio": "Request ratio scope separately when expanded bytes are at least 256 MiB and strictly exceed compressed bytes times 1000. Check ZIP members, 7z solid folders and totals, and complete compressed TAR/GZip streams. Use u128 arithmetic; unknown compressed length does not become zero. No ratio warning for legacy requests.", | |
| 233 | 추가: "ratio": "Request ratio scope separately when expanded bytes are at least 256 MiB and strictly exceed compressed bytes times 1000. Check ZIP members and aggregate payload totals, 7z solid folders and totals, and complete compressed TAR/GZip streams. Use u128 arithmetic; unknown compressed length does not become zero. No ratio warning for legacy requests.", | |
| 234 | 234 | "accounting": "Monitor declared catalog sums and counts, real decoded bytes, per-stream ratios and source-plan sums. Decoders must match verified declared lengths before publication. For compressed TAR/GZip the expanded stream includes headers/padding. ZIP creation ceiling counts source logical bytes; ZIP/container/encryption overhead is separately space-checked.", |
| 235 | 235 | "disk": "Continue staging/destination volume preflight and per-chunk space checks after approval. available_bytes is advisory free space on the current observation storage volume, not a reservation or all-volume total. Unknown storage is None. Preserve DiskFull, partial publication, durability and cleanup semantics.", |
| 236 | 236 | "waiting": "One resource, password or conflict challenge at a time. Pause processing while waiting; control reader remains live for Cancel. Response EOF fails Protocol. Guarded challenge wait is limited to 300 seconds per question; reset the inactivity clock after a valid reply, excluding the human wait.", |
| 237 | 237 | "time": "Legacy and unapproved jobs retain their whole-job 300-second deadline. After the first resource grant, use a 60-second inactivity deadline measured only from actual read/decode/write/metadata progress, not repeated cancellation checks or outgoing heartbeats. Cooperative checkpoints cannot forcibly interrupt a blocked OS call.", |
| 238 | 238 | "hard_ceiling": "Output/source bytes <=64 GiB and entries<=200000, including after approval. Caller may lower both ceilings for normal operation or scaled tests. Input quota cannot be expanded. Existing path, metadata, dictionary, frame and source-identity limits remain independent.", |
| 239 | 삭제: "open_constraint": "The unchanged 8 MiB MetadataBudget and 32768 node cap currently prevent reaching 200000 entries, and source paths consume the same budget. Metadata storage/budget policy requires a manager decision before claiming support for 200000 real entries. Keep the PR draft until this and frontend activation are resolved.", | |
| 239 | 추가: "metadata": "Only after a valid ResourceReply(allow=true) for this job, select 64 MiB MetadataBudget and 262144 nodes, including ZIP/TAR/7z parsing, decoded 7z headers, XZ index/block bounds, member/path validation, implicit output parents and source planning. Legacy Start/StartInteractive, unapproved guarded jobs and slice APIs keep 8 MiB and 32768 nodes. Merely requesting expanded ceilings does not grant a larger budget. Names and source paths still consume checked byte budgets and implicit parents consume nodes, so long/deep paths can hit the metadata cap before 200000 entries. Approved source-path/pending-name copies consume bytes without duplicating their entry node. Expanded metadata jobs do not retain a universal 64 MiB RSS target. Frontend activation remains pending.", | |
| 240 | 240 | "tests": "Use numeric 16/64 GiB and 10000/200000 policy boundaries, scaled worker limits, a compressed 257 MiB zero stream, and a virtual clock for the 60-second stall. Do not write 64 GiB in tests." |
| 241 | 241 | } |
| 242 | 242 | } |
| @@ -7,30 +7,74 @@ pub const MAX_PATH_DEPTH: usize = 64; | ||
| 7 | 7 | pub const MAX_METADATA_BYTES: usize = 8 * 1024 * 1024; |
| 8 | 8 | pub const MAX_OUTPUT_NODES: usize = 32_768; |
| 9 | 9 | |
| 10 | 추가: #[derive(Clone, Copy, Debug, Eq, PartialEq)] | |
| 11 | 추가: pub struct MetadataLimits { | |
| 12 | 추가: pub(crate) bytes: usize, | |
| 13 | 추가: pub(crate) nodes: usize, | |
| 14 | 추가: pub(crate) enlarged: bool, | |
| 15 | 추가: } | |
| 16 | 추가: impl Default for MetadataLimits { | |
| 17 | 추가: fn default() -> Self { | |
| 18 | 추가: Self { | |
| 19 | 추가: bytes: MAX_METADATA_BYTES, | |
| 20 | 추가: nodes: MAX_OUTPUT_NODES, | |
| 21 | 추가: enlarged: false, | |
| 22 | 추가: } | |
| 23 | 추가: } | |
| 24 | 추가: } | |
| 25 | 추가: impl MetadataLimits { | |
| 26 | 추가: pub(crate) fn approved() -> Self { | |
| 27 | 추가: Self { | |
| 28 | 추가: bytes: 64 * 1024 * 1024, | |
| 29 | 추가: nodes: 262_144, | |
| 30 | 추가: enlarged: true, | |
| 31 | 추가: } | |
| 32 | 추가: } | |
| 33 | 추가: } | |
| 34 | 추가: | |
| 10 | 35 | #[derive(Default)] |
| 11 | 36 | pub(crate) struct MetadataBudget { |
| 12 | 37 | bytes: usize, |
| 13 | 38 | nodes: usize, |
| 14 | 39 | } |
| 15 | 40 | impl MetadataBudget { |
| 41 | 추가: fn charge_cost(&mut self, bytes: usize, nodes: usize, limits: MetadataLimits) -> Result<()> { | |
| 42 | 추가: let bytes = self | |
| 43 | 추가: .bytes | |
| 44 | 추가: .checked_add(bytes) | |
| 45 | 추가: .filter(|n| *n <= limits.bytes) | |
| 46 | 추가: .ok_or(ErrorCode::Limit)?; | |
| 47 | 추가: let nodes = self | |
| 48 | 추가: .nodes | |
| 49 | 추가: .checked_add(nodes) | |
| 50 | 추가: .filter(|n| *n <= limits.nodes) | |
| 51 | 추가: .ok_or(ErrorCode::Limit)?; | |
| 52 | 추가: self.bytes = bytes; | |
| 53 | 추가: self.nodes = nodes; | |
| 54 | 추가: Ok(()) | |
| 55 | 추가: } | |
| 16 | 56 | pub(crate) fn charge(&mut self, name: &str) -> Result<()> { |
| 57 | 추가: self.charge_with(name, MetadataLimits::default()) | |
| 58 | 추가: } | |
| 59 | 추가: pub(crate) fn charge_with(&mut self, name: &str, limits: MetadataLimits) -> Result<()> { | |
| 17 | 60 | // 이름 복제와 인덱스 노드 비용을 할당 전에 계산함. |
| 18 | 61 | let cost = name |
| 19 | 62 | .len() |
| 20 | 63 | .checked_mul(4) |
| 21 | 64 | .and_then(|n| n.checked_add(256)) |
| 22 | 65 | .ok_or(ErrorCode::Limit)?; |
| 23 | 삭제: self.bytes = self | |
| 24 | 삭제: .bytes | |
| 25 | 삭제: .checked_add(cost) | |
| 26 | 삭제: .filter(|n| *n <= MAX_METADATA_BYTES) | |
| 27 | 삭제: .ok_or(ErrorCode::Limit)?; | |
| 28 | 삭제: self.nodes = self | |
| 29 | 삭제: .nodes | |
| 30 | 삭제: .checked_add(1) | |
| 31 | 삭제: .filter(|n| *n <= MAX_OUTPUT_NODES) | |
| 32 | 삭제: .ok_or(ErrorCode::Limit)?; | |
| 33 | 삭제: Ok(()) | |
| 66 | 추가: self.charge_cost(cost, 1, limits) | |
| 67 | 추가: } | |
| 68 | 추가: pub(crate) fn charge_copy(&mut self, name: &str, limits: MetadataLimits) -> Result<()> { | |
| 69 | 추가: if !limits.enlarged { | |
| 70 | 추가: return self.charge_with(name, limits); | |
| 71 | 추가: } | |
| 72 | 추가: // 확대 계획의 경로와 대기 이름은 기존 항목 노드에 속한 복사 비용임. | |
| 73 | 추가: self.charge_cost( | |
| 74 | 추가: name.len().checked_mul(4).ok_or(ErrorCode::Limit)?, | |
| 75 | 추가: 0, | |
| 76 | 추가: limits, | |
| 77 | 추가: ) | |
| 34 | 78 | } |
| 35 | 79 | } |
| 36 | 80 | |
| @@ -99,10 +143,17 @@ pub fn valid_name(name: &str, directory: bool) -> Result<String> { | ||
| 99 | 143 | Ok(name.to_owned()) |
| 100 | 144 | } |
| 101 | 145 | pub fn validate_members(members: &[Member]) -> Result<()> { |
| 146 | 추가: validate_members_with(members, &mut || Ok(())) | |
| 147 | 추가: } | |
| 148 | 추가: pub(crate) fn validate_members_with( | |
| 149 | 추가: members: &[Member], | |
| 150 | 추가: check: &mut impl crate::resources::Monitor, | |
| 151 | 추가: ) -> Result<()> { | |
| 102 | 152 | let mut names = BTreeMap::<String, bool>::new(); |
| 103 | 153 | let mut budget = MetadataBudget::default(); |
| 104 | 154 | for member in members { |
| 105 | 삭제: budget.charge(&member.entry.name)?; | |
| 155 | 추가: check.activity()?; | |
| 156 | 추가: budget.charge_with(&member.entry.name, check.metadata_limits())?; | |
| 106 | 157 | let directory = member.entry.kind == EntryKind::Directory; |
| 107 | 158 | let name = valid_name(&member.entry.name, directory)?.to_lowercase(); |
| 108 | 159 | if names.insert(name, directory).is_some() { |
| @@ -110,6 +161,7 @@ pub fn validate_members(members: &[Member]) -> Result<()> { | ||
| 110 | 161 | } |
| 111 | 162 | } |
| 112 | 163 | for name in names.keys() { |
| 164 | 추가: check.activity()?; | |
| 113 | 165 | let mut parent = name.as_str(); |
| 114 | 166 | while let Some((p, _)) = parent.rsplit_once('/') { |
| 115 | 167 | if names.get(p) == Some(&false) { |
| @@ -120,19 +172,23 @@ pub fn validate_members(members: &[Member]) -> Result<()> { | ||
| 120 | 172 | } |
| 121 | 173 | Ok(()) |
| 122 | 174 | } |
| 123 | 삭제: pub(crate) fn output_directories(members: &[Member]) -> Result<BTreeSet<String>> { | |
| 124 | 삭제: validate_members(members)?; | |
| 175 | 추가: pub(crate) fn output_directories( | |
| 176 | 추가: members: &[Member], | |
| 177 | 추가: check: &mut impl crate::resources::Monitor, | |
| 178 | 추가: ) -> Result<BTreeSet<String>> { | |
| 179 | 추가: validate_members_with(members, check)?; | |
| 125 | 180 | let mut budget = MetadataBudget::default(); |
| 126 | 181 | let mut dirs = BTreeSet::new(); |
| 127 | 182 | for member in members { |
| 128 | 삭제: budget.charge(&member.entry.name)?; | |
| 183 | 추가: check.activity()?; | |
| 184 | 추가: budget.charge_with(&member.entry.name, check.metadata_limits())?; | |
| 129 | 185 | if member.entry.kind == EntryKind::Directory && !dirs.contains(member.entry.name.as_str()) { |
| 130 | 186 | dirs.insert(member.entry.name.clone()); |
| 131 | 187 | } |
| 132 | 188 | let mut name = member.entry.name.as_str(); |
| 133 | 189 | while let Some((parent, _)) = name.rsplit_once('/') { |
| 134 | 190 | if !dirs.contains(parent) { |
| 135 | 삭제: budget.charge(parent)?; | |
| 191 | 추가: budget.charge_with(parent, check.metadata_limits())?; | |
| 136 | 192 | dirs.insert(parent.to_owned()); |
| 137 | 193 | } |
| 138 | 194 | name = parent; |
| @@ -816,3 +872,7 @@ pub fn create_zip_with_password( | ||
| 816 | 872 | bounded_append(&mut out, &end, limits.output)?; |
| 817 | 873 | Ok(out) |
| 818 | 874 | } |
| 875 | 추가: | |
| 876 | 추가: #[cfg(test)] | |
| 877 | 추가: #[path = "../../../tests/rust-archive-worker/metadata_policy.rs"] | |
| 878 | 추가: mod metadata_tests; |
| @@ -319,7 +319,7 @@ fn xz_layout( | ||
| 319 | 319 | end = at; |
| 320 | 320 | } |
| 321 | 321 | streams += 1; |
| 322 | 삭제: if streams > crate::archive::MAX_OUTPUT_NODES { | |
| 322 | 추가: if streams > check.metadata_limits().nodes { | |
| 323 | 323 | return Err(ErrorCode::Limit); |
| 324 | 324 | } |
| 325 | 325 | let footer_at = end.checked_sub(12).ok_or(ErrorCode::Integrity)?; |
| @@ -331,7 +331,7 @@ fn xz_layout( | ||
| 331 | 331 | return Err(ErrorCode::Integrity); |
| 332 | 332 | } |
| 333 | 333 | let index_len = (u64::from(u32::from_le_bytes(footer[4..8].try_into().unwrap())) + 1) * 4; |
| 334 | 삭제: if index_len > crate::archive::MAX_METADATA_BYTES as u64 { | |
| 334 | 추가: if index_len > check.metadata_limits().bytes as u64 { | |
| 335 | 335 | return Err(ErrorCode::Limit); |
| 336 | 336 | } |
| 337 | 337 | if index_len < 8 { |
| @@ -351,7 +351,7 @@ fn xz_layout( | ||
| 351 | 351 | } |
| 352 | 352 | let mut cursor = 1; |
| 353 | 353 | let count = vli(&index[..data_end], &mut cursor)?; |
| 354 | 삭제: if count > crate::archive::MAX_OUTPUT_NODES as u64 { | |
| 354 | 추가: if count > check.metadata_limits().nodes as u64 { | |
| 355 | 355 | return Err(ErrorCode::Limit); |
| 356 | 356 | } |
| 357 | 357 | let mut blocks = 0u64; |
| @@ -233,7 +233,7 @@ impl Plan { | ||
| 233 | 233 | data: Vec::new(), |
| 234 | 234 | }) |
| 235 | 235 | .collect::<Vec<_>>(); |
| 236 | 삭제: archive::validate_members(&members)?; | |
| 236 | 추가: archive::validate_members_with(&members, check)?; | |
| 237 | 237 | Ok(plan) |
| 238 | 238 | } |
| 239 | 239 | fn visit( |
| @@ -250,8 +250,9 @@ impl Plan { | ||
| 250 | 250 | let metadata: Metadata = input.file.metadata().map_err(crate::space::io_error)?; |
| 251 | 251 | let directory = metadata.is_dir(); |
| 252 | 252 | let name = archive::valid_name(&name, directory)?; |
| 253 | 삭제: self.budget.charge(&name)?; | |
| 254 | 삭제: self.budget.charge(&path.to_string_lossy())?; | |
| 253 | 추가: self.budget.charge_with(&name, check.metadata_limits())?; | |
| 254 | 추가: self.budget | |
| 255 | 추가: .charge_copy(&path.to_string_lossy(), check.metadata_limits())?; | |
| 255 | 256 | let size = if directory { 0 } else { metadata.len() }; |
| 256 | 257 | self.total = self |
| 257 | 258 | .total |
| @@ -299,7 +300,7 @@ impl Plan { | ||
| 299 | 300 | .file_name() |
| 300 | 301 | .into_string() |
| 301 | 302 | .map_err(|_| ErrorCode::UnsafePath)?; |
| 302 | 삭제: self.budget.charge(&leaf)?; | |
| 303 | 추가: self.budget.charge_copy(&leaf, check.metadata_limits())?; | |
| 303 | 304 | children.push(leaf); |
| 304 | 305 | check.observe( |
| 305 | 306 | ResourceUsage { |
| @@ -4,6 +4,9 @@ use std::time::Duration; | ||
| 4 | 4 | type Result<T> = std::result::Result<T, ErrorCode>; |
| 5 | 5 | |
| 6 | 6 | pub trait Monitor { |
| 7 | 추가: fn metadata_limits(&self) -> crate::archive::MetadataLimits { | |
| 8 | 추가: crate::archive::MetadataLimits::default() | |
| 9 | 추가: } | |
| 7 | 10 | fn check(&mut self) -> Result<()>; |
| 8 | 11 | fn activity(&mut self) -> Result<()> { |
| 9 | 12 | self.check() |
| @@ -24,6 +27,13 @@ pub(crate) struct Budget { | ||
| 24 | 27 | pub granted: ResourceScope, |
| 25 | 28 | } |
| 26 | 29 | impl Budget { |
| 30 | 추가: pub fn metadata_limits(&self) -> crate::archive::MetadataLimits { | |
| 31 | 추가: if self.granted.any() { | |
| 32 | 추가: crate::archive::MetadataLimits::approved() | |
| 33 | 추가: } else { | |
| 34 | 추가: crate::archive::MetadataLimits::default() | |
| 35 | 추가: } | |
| 36 | 추가: } | |
| 27 | 37 | pub fn required(&self, usage: ResourceUsage) -> Result<ResourceScope> { |
| 28 | 38 | let bytes = usage |
| 29 | 39 | .estimated_bytes |
| @@ -430,6 +430,7 @@ impl<W: Write> Job<W> { | ||
| 430 | 430 | for member in &catalog.members { |
| 431 | 431 | self.check()?; |
| 432 | 432 | self.event(Message::Entry(member.entry.clone()))?; |
| 433 | 추가: self.activity()?; | |
| 433 | 434 | } |
| 434 | 435 | self.event(Message::ListEnd { |
| 435 | 436 | entry_count: catalog.members.len() as u32, |
| @@ -547,7 +548,7 @@ impl<W: Write> Job<W> { | ||
| 547 | 548 | .is_none_or(|s| s.contains(&m.entry.entry_id)) |
| 548 | 549 | }) |
| 549 | 550 | .collect::<Vec<_>>(); |
| 550 | 삭제: let dirs = archive::output_directories(&members)?; | |
| 551 | 추가: let dirs = archive::output_directories(&members, self)?; | |
| 551 | 552 | let files = members |
| 552 | 553 | .iter() |
| 553 | 554 | .filter(|m| m.entry.kind == EntryKind::File) |
| @@ -681,6 +682,11 @@ impl<W: Write> Job<W> { | ||
| 681 | 682 | } |
| 682 | 683 | } |
| 683 | 684 | impl<W: Write> Monitor for Job<W> { |
| 685 | 추가: fn metadata_limits(&self) -> archive::MetadataLimits { | |
| 686 | 추가: self.budget | |
| 687 | 추가: .as_ref() | |
| 688 | 추가: .map_or_else(archive::MetadataLimits::default, |b| b.metadata_limits()) | |
| 689 | 추가: } | |
| 684 | 690 | fn check(&mut self) -> Result<()> { |
| 685 | 691 | Job::check(self) |
| 686 | 692 | } |
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | use crate::{ |
| 2 | 삭제: archive::{MAX_METADATA_BYTES, Member, MetadataBudget, valid_name, validate_members}, | |
| 2 | 추가: archive::{Member, MetadataBudget, valid_name, validate_members_with}, | |
| 3 | 3 | protocol::*, |
| 4 | 4 | }; |
| 5 | 5 | use std::collections::BTreeSet; |
| @@ -403,6 +403,7 @@ fn files( | ||
| 403 | 403 | r: &mut Reader<'_>, |
| 404 | 404 | limits: Limits, |
| 405 | 405 | streams: Option<&Streams>, |
| 406 | 추가: check: &mut impl crate::resources::Monitor, | |
| 406 | 407 | ) -> Result<(Vec<Member>, Vec<usize>)> { |
| 407 | 408 | let count = r.number(limits.entries as usize)?; |
| 408 | 409 | let mut empty = vec![false; count]; |
| @@ -418,7 +419,7 @@ fn files( | ||
| 418 | 419 | if !seen.insert(property) { |
| 419 | 420 | return Err(ErrorCode::Integrity); |
| 420 | 421 | } |
| 421 | 삭제: let len = r.number(MAX_METADATA_BYTES)?; | |
| 422 | 추가: let len = r.number(check.metadata_limits().bytes)?; | |
| 422 | 423 | let mut value = Reader::new(r.take(len)?); |
| 423 | 424 | match property { |
| 424 | 425 | 14 => { |
| @@ -443,6 +444,7 @@ fn files( | ||
| 443 | 444 | let mut decoded = Vec::new(); |
| 444 | 445 | let mut budget = MetadataBudget::default(); |
| 445 | 446 | for _ in 0..count { |
| 447 | 추가: check.activity()?; | |
| 446 | 448 | let mut units = Vec::new(); |
| 447 | 449 | loop { |
| 448 | 450 | let n = u16::from_le_bytes(value.take(2)?.try_into().unwrap()); |
| @@ -455,7 +457,7 @@ fn files( | ||
| 455 | 457 | units.push(n); |
| 456 | 458 | } |
| 457 | 459 | let name = String::from_utf16(&units).map_err(|_| ErrorCode::Integrity)?; |
| 458 | 삭제: budget.charge(&name)?; | |
| 460 | 추가: budget.charge_with(&name, check.metadata_limits())?; | |
| 459 | 461 | decoded.push(name); |
| 460 | 462 | } |
| 461 | 463 | names = Some(decoded); |
| @@ -549,7 +551,7 @@ fn files( | ||
| 549 | 551 | if descriptions.next().is_some() { |
| 550 | 552 | return Err(ErrorCode::Integrity); |
| 551 | 553 | } |
| 552 | 삭제: validate_members(&members)?; | |
| 554 | 추가: validate_members_with(&members, check)?; | |
| 553 | 555 | Ok((members, stream_indices)) |
| 554 | 556 | } |
| 555 | 557 | pub(crate) fn open( |
| @@ -580,7 +582,7 @@ pub(crate) fn open( | ||
| 580 | 582 | } |
| 581 | 583 | let offset = u64::from_le_bytes(header[12..20].try_into().unwrap()); |
| 582 | 584 | let len = u64::from_le_bytes(header[20..28].try_into().unwrap()); |
| 583 | 삭제: if len > MAX_METADATA_BYTES as u64 { | |
| 585 | 추가: if len > check.metadata_limits().bytes as u64 { | |
| 584 | 586 | return Err(ErrorCode::Limit); |
| 585 | 587 | } |
| 586 | 588 | let start = offset.checked_add(32).ok_or(ErrorCode::Integrity)?; |
| @@ -613,7 +615,7 @@ pub(crate) fn open( | ||
| 613 | 615 | if bytes[0] == 23 { |
| 614 | 616 | let mut r = Reader::new(&bytes[1..]); |
| 615 | 617 | let header_limits = Limits { |
| 616 | 삭제: output: MAX_METADATA_BYTES as u64, | |
| 618 | 추가: output: check.metadata_limits().bytes as u64, | |
| 617 | 619 | ..limits |
| 618 | 620 | }; |
| 619 | 621 | let streams = Streams::read(&mut r, header_limits)?; |
| @@ -638,7 +640,7 @@ pub(crate) fn open( | ||
| 638 | 640 | let mut tag = r.byte()?; |
| 639 | 641 | if tag == 2 { |
| 640 | 642 | while r.byte()? != 0 { |
| 641 | 삭제: let len = r.number(MAX_METADATA_BYTES)?; | |
| 643 | 추가: let len = r.number(check.metadata_limits().bytes)?; | |
| 642 | 644 | r.take(len)?; |
| 643 | 645 | } |
| 644 | 646 | tag = r.byte()?; |
| @@ -651,7 +653,7 @@ pub(crate) fn open( | ||
| 651 | 653 | tag = r.byte()?; |
| 652 | 654 | } |
| 653 | 655 | let (members, stream_indices) = if tag == 5 { |
| 654 | 삭제: let f = files(&mut r, limits, streams.as_ref())?; | |
| 656 | 추가: let f = files(&mut r, limits, streams.as_ref(), check)?; | |
| 655 | 657 | tag = r.byte()?; |
| 656 | 658 | f |
| 657 | 659 | } else { |
| @@ -211,7 +211,7 @@ fn tar( | ||
| 211 | 211 | if cursor > len { |
| 212 | 212 | return Err(ErrorCode::Integrity); |
| 213 | 213 | } |
| 214 | 삭제: metadata.charge(&name)?; | |
| 214 | 추가: metadata.charge_with(&name, check.metadata_limits())?; | |
| 215 | 215 | let name = archive::valid_name(&name, kind == EntryKind::Directory)?; |
| 216 | 216 | offsets.push(start); |
| 217 | 217 | members.push(Member { |
| @@ -226,7 +226,7 @@ fn tar( | ||
| 226 | 226 | data: Vec::new(), |
| 227 | 227 | }); |
| 228 | 228 | } |
| 229 | 삭제: archive::validate_members(&members)?; | |
| 229 | 추가: archive::validate_members_with(&members, check)?; | |
| 230 | 230 | Ok(Catalog { |
| 231 | 231 | format, |
| 232 | 232 | members, |
| @@ -591,7 +591,7 @@ fn zip( | ||
| 591 | 591 | if kind == EntryKind::Directory && size != 0 { |
| 592 | 592 | return Err(ErrorCode::Integrity); |
| 593 | 593 | } |
| 594 | 삭제: metadata.charge(name)?; | |
| 594 | 추가: metadata.charge_with(name, check.metadata_limits())?; | |
| 595 | 595 | let name = archive::valid_name(name, kind == EntryKind::Directory)?; |
| 596 | 596 | if add(local, 30)? > central { |
| 597 | 597 | return Err(ErrorCode::Integrity); |
| @@ -690,7 +690,7 @@ fn zip( | ||
| 690 | 690 | if next != central { |
| 691 | 691 | return Err(ErrorCode::Integrity); |
| 692 | 692 | } |
| 693 | 삭제: archive::validate_members(&members)?; | |
| 693 | 추가: archive::validate_members_with(&members, check)?; | |
| 694 | 694 | // 작은 항목으로 나뉜 고압축 입력도 디코딩 전에 합계로 확인함. |
| 695 | 695 | check.observe( |
| 696 | 696 | ResourceUsage { |
| @@ -681,3 +681,76 @@ fn publication_still_stops_after_sixty_seconds_without_progress() { | ||
| 681 | 681 | assert_eq!(terminal(&events).created_count, 0); |
| 682 | 682 | assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 0); |
| 683 | 683 | } |
| 684 | 추가: | |
| 685 | 추가: #[test] | |
| 686 | 추가: fn approved_list_reaches_two_hundred_thousand_short_entries() { | |
| 687 | 추가: let s = setup(); | |
| 688 | 추가: generate(&s, "many-entries"); | |
| 689 | 추가: let mut start = request(&s, Limits::default().output, Limits::default().output); | |
| 690 | 추가: start.start.action = Action::List { | |
| 691 | 추가: archive: s.path("input"), | |
| 692 | 추가: }; | |
| 693 | 추가: start.ceiling.entries = start.start.limits.entries; | |
| 694 | 추가: let events = run(&s, start.clone(), |_| None); | |
| 695 | 추가: assert_eq!(terminal(&events).error, ErrorCode::Limit); | |
| 696 | 추가: assert!( | |
| 697 | 추가: !events | |
| 698 | 추가: .iter() | |
| 699 | 추가: .any(|e| matches!(e, Message::ResourceRequired { .. })) | |
| 700 | 추가: ); | |
| 701 | 추가: start.ceiling.entries = 200_000; | |
| 702 | 추가: let events = run(&s, start, approve); | |
| 703 | 추가: assert_eq!( | |
| 704 | 추가: terminal(&events).outcome, | |
| 705 | 추가: Outcome::Completed, | |
| 706 | 추가: "{:?}", | |
| 707 | 추가: terminal(&events) | |
| 708 | 추가: ); | |
| 709 | 추가: let count = events | |
| 710 | 추가: .iter() | |
| 711 | 추가: .filter_map(|e| match e { | |
| 712 | 추가: Message::Entry(entry) => Some(entry), | |
| 713 | 추가: _ => None, | |
| 714 | 추가: }) | |
| 715 | 추가: .enumerate() | |
| 716 | 추가: .map(|(i, entry)| { | |
| 717 | 추가: assert_eq!(entry.entry_id, i as u32); | |
| 718 | 추가: assert_eq!(entry.name, format!("e{i}")); | |
| 719 | 추가: }) | |
| 720 | 추가: .count(); | |
| 721 | 추가: assert_eq!(count, 200_000); | |
| 722 | 추가: assert_eq!(terminal(&events).created_count, 0); | |
| 723 | 추가: } | |
| 724 | 추가: | |
| 725 | 추가: #[test] | |
| 726 | 추가: fn metadata_growth_requires_a_grant_even_below_entry_and_output_caps() { | |
| 727 | 추가: let s = setup(); | |
| 728 | 추가: generate(&s, "wide-names"); | |
| 729 | 추가: let mut start = request(&s, 1, 1); | |
| 730 | 추가: start.start.action = Action::List { | |
| 731 | 추가: archive: s.path("input"), | |
| 732 | 추가: }; | |
| 733 | 추가: start.ceiling.entries = start.start.limits.entries; | |
| 734 | 추가: let events = run(&s, start.clone(), |_| None); | |
| 735 | 추가: assert_eq!(terminal(&events).error, ErrorCode::Limit); | |
| 736 | 추가: assert!( | |
| 737 | 추가: !events | |
| 738 | 추가: .iter() | |
| 739 | 추가: .any(|e| matches!(e, Message::ResourceRequired { .. } | Message::Entry(_))) | |
| 740 | 추가: ); | |
| 741 | 추가: start.ceiling.output = 2; | |
| 742 | 추가: let events = run(&s, start, approve); | |
| 743 | 추가: assert_eq!( | |
| 744 | 추가: terminal(&events).outcome, | |
| 745 | 추가: Outcome::Completed, | |
| 746 | 추가: "{:?}", | |
| 747 | 추가: terminal(&events) | |
| 748 | 추가: ); | |
| 749 | 추가: assert_eq!( | |
| 750 | 추가: events | |
| 751 | 추가: .iter() | |
| 752 | 추가: .filter(|e| matches!(e, Message::Entry(_))) | |
| 753 | 추가: .count(), | |
| 754 | 추가: 9000 | |
| 755 | 추가: ); | |
| 756 | 추가: } |
| @@ -13,6 +13,14 @@ if case == "bomb": | ||
| 13 | 13 | block = bytes(1024 * 1024) |
| 14 | 14 | for _ in range(257): |
| 15 | 15 | output.write(block) |
| 16 | 추가: elif case == "wide-names": | |
| 17 | 추가: with zipfile.ZipFile(root / "input", "w") as archive: | |
| 18 | 추가: for entry_id in range(9000): | |
| 19 | 추가: archive.writestr(f"{entry_id:04}" + "x" * 236, b"") | |
| 20 | 추가: elif case == "many-entries": | |
| 21 | 추가: with zipfile.ZipFile(root / "input", "w") as archive: | |
| 22 | 추가: for entry_id in range(200_000): | |
| 23 | 추가: archive.writestr(f"e{entry_id}", b"") | |
| 16 | 24 | elif case == "empty-directories": |
| 17 | 25 | with zipfile.ZipFile(root / "input", "w") as archive: |
| 18 | 26 | for entry_id in range(36): |
| @@ -0,0 +1,174 @@ | ||
| 1 | 추가: use super::*; | |
| 2 | 추가: use crate::resources::{Budget, Monitor}; | |
| 3 | 추가: | |
| 4 | 추가: struct Policy(MetadataLimits); | |
| 5 | 추가: impl Monitor for Policy { | |
| 6 | 추가: fn check(&mut self) -> Result<()> { | |
| 7 | 추가: Ok(()) | |
| 8 | 추가: } | |
| 9 | 추가: fn metadata_limits(&self) -> MetadataLimits { | |
| 10 | 추가: self.0 | |
| 11 | 추가: } | |
| 12 | 추가: } | |
| 13 | 추가: fn approved(bytes: usize, nodes: usize) -> MetadataLimits { | |
| 14 | 추가: MetadataLimits { | |
| 15 | 추가: bytes, | |
| 16 | 추가: nodes, | |
| 17 | 추가: ..MetadataLimits::approved() | |
| 18 | 추가: } | |
| 19 | 추가: } | |
| 20 | 추가: fn member(name: &str) -> Member { | |
| 21 | 추가: Member { | |
| 22 | 추가: entry: Entry { | |
| 23 | 추가: entry_id: 0, | |
| 24 | 추가: name: name.into(), | |
| 25 | 추가: kind: EntryKind::File, | |
| 26 | 추가: size: 0, | |
| 27 | 추가: compressed_size: 0, | |
| 28 | 추가: encrypted: false, | |
| 29 | 추가: }, | |
| 30 | 추가: data: Vec::new(), | |
| 31 | 추가: } | |
| 32 | 추가: } | |
| 33 | 추가: | |
| 34 | 추가: #[test] | |
| 35 | 추가: fn only_a_grant_selects_expanded_metadata_policy() { | |
| 36 | 추가: let soft = Limits::default(); | |
| 37 | 추가: let mut b = Budget { | |
| 38 | 추가: soft, | |
| 39 | 추가: ceiling: Limits { | |
| 40 | 추가: entries: 200_000, | |
| 41 | 추가: output: 64 * 1024 * 1024 * 1024, | |
| 42 | 추가: ..soft | |
| 43 | 추가: }, | |
| 44 | 추가: granted: ResourceScope::default(), | |
| 45 | 추가: }; | |
| 46 | 추가: assert_eq!(b.metadata_limits(), MetadataLimits::default()); | |
| 47 | 추가: for scope in [ | |
| 48 | 추가: ResourceScope { | |
| 49 | 추가: output: true, | |
| 50 | 추가: ..ResourceScope::default() | |
| 51 | 추가: }, | |
| 52 | 추가: ResourceScope { | |
| 53 | 추가: entries: true, | |
| 54 | 추가: ..ResourceScope::default() | |
| 55 | 추가: }, | |
| 56 | 추가: ResourceScope { | |
| 57 | 추가: ratio: true, | |
| 58 | 추가: ..ResourceScope::default() | |
| 59 | 추가: }, | |
| 60 | 추가: ] { | |
| 61 | 추가: b.granted = ResourceScope::default(); | |
| 62 | 추가: b.grant(scope); | |
| 63 | 추가: assert_eq!(b.metadata_limits(), MetadataLimits::approved()); | |
| 64 | 추가: } | |
| 65 | 추가: assert_eq!(MetadataLimits::default().bytes, 8 * 1024 * 1024); | |
| 66 | 추가: assert_eq!(MetadataLimits::default().nodes, 32_768); | |
| 67 | 추가: assert_eq!(MetadataLimits::approved().bytes, 64 * 1024 * 1024); | |
| 68 | 추가: assert_eq!(MetadataLimits::approved().nodes, 262_144); | |
| 69 | 추가: assert_eq!( | |
| 70 | 추가: Policy(MetadataLimits::default()).metadata_limits(), | |
| 71 | 추가: MetadataLimits::default() | |
| 72 | 추가: ); | |
| 73 | 추가: assert_eq!((|| Ok(())).metadata_limits(), MetadataLimits::default()); | |
| 74 | 추가: } | |
| 75 | 추가: | |
| 76 | 추가: #[test] | |
| 77 | 추가: fn scaled_byte_and_node_caps_are_independent_and_atomic() { | |
| 78 | 추가: let limits = approved(524, 2); | |
| 79 | 추가: let mut b = MetadataBudget::default(); | |
| 80 | 추가: b.charge_with("a", limits).unwrap(); | |
| 81 | 추가: b.charge_with("bb", limits).unwrap(); | |
| 82 | 추가: assert_eq!((b.bytes, b.nodes), (524, 2)); | |
| 83 | 추가: assert_eq!(b.charge_with("", limits), Err(ErrorCode::Limit)); | |
| 84 | 추가: assert_eq!((b.bytes, b.nodes), (524, 2)); | |
| 85 | 추가: let mut b = MetadataBudget::default(); | |
| 86 | 추가: b.charge_with("a", approved(1000, 1)).unwrap(); | |
| 87 | 추가: assert_eq!(b.charge_with("b", approved(1000, 1)), Err(ErrorCode::Limit)); | |
| 88 | 추가: assert_eq!(b.charge_with("aa", approved(263, 2)), Err(ErrorCode::Limit)); | |
| 89 | 추가: assert_eq!((b.bytes, b.nodes), (260, 1)); | |
| 90 | 추가: } | |
| 91 | 추가: | |
| 92 | 추가: #[test] | |
| 93 | 추가: fn approved_source_path_copies_consume_bytes_without_duplicate_nodes() { | |
| 94 | 추가: let mut b = MetadataBudget::default(); | |
| 95 | 추가: let limits = approved(300, 1); | |
| 96 | 추가: b.charge_with("a", limits).unwrap(); | |
| 97 | 추가: b.charge_copy("/source/a", limits).unwrap(); | |
| 98 | 추가: b.charge_copy("a", limits).unwrap(); | |
| 99 | 추가: assert_eq!((b.bytes, b.nodes), (300, 1)); | |
| 100 | 추가: assert_eq!(b.charge_copy("b", limits), Err(ErrorCode::Limit)); | |
| 101 | 추가: let mut legacy = MetadataBudget::default(); | |
| 102 | 추가: legacy.charge_with("a", MetadataLimits::default()).unwrap(); | |
| 103 | 추가: legacy | |
| 104 | 추가: .charge_copy("/source/a", MetadataLimits::default()) | |
| 105 | 추가: .unwrap(); | |
| 106 | 추가: assert_eq!(legacy.nodes, 2); | |
| 107 | 추가: } | |
| 108 | 추가: | |
| 109 | 추가: #[test] | |
| 110 | 추가: fn directory_planning_counts_implicit_parents_in_its_budget() { | |
| 111 | 추가: let members = vec![member("a/b")]; | |
| 112 | 추가: assert_eq!( | |
| 113 | 추가: output_directories(&members, &mut Policy(approved(528, 2))) | |
| 114 | 추가: .unwrap() | |
| 115 | 추가: .into_iter() | |
| 116 | 추가: .collect::<Vec<_>>(), | |
| 117 | 추가: vec!["a"] | |
| 118 | 추가: ); | |
| 119 | 추가: assert_eq!( | |
| 120 | 추가: output_directories(&members, &mut Policy(approved(527, 2))), | |
| 121 | 추가: Err(ErrorCode::Limit) | |
| 122 | 추가: ); | |
| 123 | 추가: assert_eq!( | |
| 124 | 추가: output_directories(&members, &mut Policy(approved(528, 1))), | |
| 125 | 추가: Err(ErrorCode::Limit) | |
| 126 | 추가: ); | |
| 127 | 추가: let conflict = vec![member("a"), member("a/b")]; | |
| 128 | 추가: assert_eq!( | |
| 129 | 추가: validate_members_with(&conflict, &mut Policy(MetadataLimits::approved())), | |
| 130 | 추가: Err(ErrorCode::Conflict) | |
| 131 | 추가: ); | |
| 132 | 추가: } | |
| 133 | 추가: | |
| 134 | 추가: #[test] | |
| 135 | 추가: fn source_plan_uses_the_selected_metadata_and_entry_caps() { | |
| 136 | 추가: let root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) | |
| 137 | 추가: .join("../../tests/rust-archive-worker/fixtures") | |
| 138 | 추가: .canonicalize() | |
| 139 | 추가: .unwrap(); | |
| 140 | 추가: let sources = ["sample.gz", "sample.tar"] | |
| 141 | 추가: .into_iter() | |
| 142 | 추가: .enumerate() | |
| 143 | 추가: .map(|(i, name)| Source { | |
| 144 | 추가: path: NativePath::from_path(&root.join(name)), | |
| 145 | 추가: archive_name: format!("source-{i}"), | |
| 146 | 추가: }) | |
| 147 | 추가: .collect::<Vec<_>>(); | |
| 148 | 추가: let limits = Limits { | |
| 149 | 추가: entries: 2, | |
| 150 | 추가: ..Limits::default() | |
| 151 | 추가: }; | |
| 152 | 추가: assert!( | |
| 153 | 추가: crate::create_sources::Plan::new(&sources, limits, &mut Policy(approved(10000, 2))).is_ok() | |
| 154 | 추가: ); | |
| 155 | 추가: assert!(matches!( | |
| 156 | 추가: crate::create_sources::Plan::new(&sources, limits, &mut Policy(approved(10000, 1))), | |
| 157 | 추가: Err(ErrorCode::Limit) | |
| 158 | 추가: )); | |
| 159 | 추가: assert!(matches!( | |
| 160 | 추가: crate::create_sources::Plan::new(&sources, limits, &mut Policy(approved(511, 2))), | |
| 161 | 추가: Err(ErrorCode::Limit) | |
| 162 | 추가: )); | |
| 163 | 추가: assert!(matches!( | |
| 164 | 추가: crate::create_sources::Plan::new( | |
| 165 | 추가: &sources, | |
| 166 | 추가: Limits { | |
| 167 | 추가: entries: 1, | |
| 168 | 추가: ..limits | |
| 169 | 추가: }, | |
| 170 | 추가: &mut Policy(approved(10000, 2)) | |
| 171 | 추가: ), | |
| 172 | 추가: Err(ErrorCode::Limit) | |
| 173 | 추가: )); | |
| 174 | 추가: } |