작업자 실제 경로 시험과 ZIP 확장 해석을 통합함
- 작성자
- 시로사키 하나
- 작성 시각
- 커밋
dee7d8c42240877d4f1de51cd2619063861bf096- 부모
- ef72c47
변경된 파일 17개
+638-287| @@ -382,39 +382,9 @@ fn tar( | ||
| 382 | 382 | validate_members(&members)?; |
| 383 | 383 | Ok(members) |
| 384 | 384 | } |
| 385 | 삭제: #[derive(Clone, Copy, PartialEq, Eq)] | |
| 386 | 삭제: pub(crate) struct AesExtra { | |
| 387 | 삭제: pub version: u16, | |
| 388 | 삭제: pub method: u16, | |
| 389 | 삭제: } | |
| 385 | 추가: pub(crate) use crate::zip_extra::AesExtra; | |
| 390 | 386 | pub(crate) fn aes_extra(extra: &[u8]) -> Result<Option<AesExtra>> { |
| 391 | 삭제: let mut at = 0; | |
| 392 | 삭제: let mut found = None; | |
| 393 | 삭제: while at < extra.len() { | |
| 394 | 삭제: let tag = u16at(extra, at)?; | |
| 395 | 삭제: let len = u16at(extra, at + 2)? as usize; | |
| 396 | 삭제: let value = part(extra, at + 4, len)?; | |
| 397 | 삭제: if tag == 1 { | |
| 398 | 삭제: return Err(ErrorCode::UnsupportedFeature); | |
| 399 | 삭제: } | |
| 400 | 삭제: if tag == 0x9901 { | |
| 401 | 삭제: if found.is_some() || len < 7 { | |
| 402 | 삭제: return Err(ErrorCode::Integrity); | |
| 403 | 삭제: } | |
| 404 | 삭제: let version = u16at(value, 0)?; | |
| 405 | 삭제: let method = u16at(value, 5)?; | |
| 406 | 삭제: if !matches!(version, 1 | 2) | |
| 407 | 삭제: || &value[2..4] != b"AE" | |
| 408 | 삭제: || value[4] != 3 | |
| 409 | 삭제: || !matches!(method, 0 | 8) | |
| 410 | 삭제: { | |
| 411 | 삭제: return Err(ErrorCode::UnsupportedFeature); | |
| 412 | 삭제: } | |
| 413 | 삭제: found = Some(AesExtra { version, method }); | |
| 414 | 삭제: } | |
| 415 | 삭제: at += 4 + len; | |
| 416 | 삭제: } | |
| 417 | 삭제: Ok(found) | |
| 387 | 추가: crate::zip_extra::parse(extra, crate::zip_extra::Policy::Classic).map(|extra| extra.aes) | |
| 418 | 388 | } |
| 419 | 389 | /// ZIP 항목 이름을 해석함. |
| 420 | 390 | /// |
| @@ -431,20 +401,7 @@ pub(crate) fn zip_name(raw: &[u8], flags: u16, extra: &[u8]) -> Result<String> { | ||
| 431 | 401 | .map(str::to_owned) |
| 432 | 402 | .map_err(|_| ErrorCode::Integrity); |
| 433 | 403 | } |
| 434 | 삭제: let mut at = 0; | |
| 435 | 삭제: let mut unicode = None; | |
| 436 | 삭제: while at < extra.len() { | |
| 437 | 삭제: let tag = u16at(extra, at)?; | |
| 438 | 삭제: let len = u16at(extra, at + 2)? as usize; | |
| 439 | 삭제: let value = part(extra, at + 4, len)?; | |
| 440 | 삭제: if tag == 0x7075 { | |
| 441 | 삭제: if unicode.is_some() || len < 5 { | |
| 442 | 삭제: return Err(ErrorCode::Integrity); | |
| 443 | 삭제: } | |
| 444 | 삭제: unicode = Some(value); | |
| 445 | 삭제: } | |
| 446 | 삭제: at += 4 + len; | |
| 447 | 삭제: } | |
| 404 | 추가: let unicode = crate::zip_extra::parse(extra, crate::zip_extra::Policy::Names)?.unicode; | |
| 448 | 405 | if let Some(value) = unicode |
| 449 | 406 | && value[0] == 1 |
| 450 | 407 | && u32::from_le_bytes(value[1..5].try_into().unwrap()) == crc32(0, raw) |
| @@ -17,4 +17,5 @@ mod split_seven_zip; | ||
| 17 | 17 | mod spool; |
| 18 | 18 | mod streaming; |
| 19 | 19 | pub mod wire; |
| 20 | 추가: mod zip_extra; | |
| 20 | 21 | mod zip_recovery; |
| @@ -3,6 +3,7 @@ use crate::{ | ||
| 3 | 3 | crypto, |
| 4 | 4 | protocol::*, |
| 5 | 5 | spool, |
| 6 | 추가: zip_extra::{self, Policy, disk_start, expanded, large_value, local_sizes}, | |
| 6 | 7 | }; |
| 7 | 8 | use std::{ |
| 8 | 9 | fs::File, |
| @@ -357,77 +358,6 @@ struct Packed { | ||
| 357 | 358 | aes: bool, |
| 358 | 359 | } |
| 359 | 360 | |
| 360 | 삭제: fn extra(bytes: &[u8]) -> Result<(Option<archive::AesExtra>, Option<Vec<u8>>)> { | |
| 361 | 삭제: let mut at = 0; | |
| 362 | 삭제: let mut aes = Vec::new(); | |
| 363 | 삭제: let mut large = None; | |
| 364 | 삭제: while at < bytes.len() { | |
| 365 | 삭제: if bytes.len() - at < 4 { | |
| 366 | 삭제: return Err(ErrorCode::Integrity); | |
| 367 | 삭제: } | |
| 368 | 삭제: let tag = u16at(bytes, at); | |
| 369 | 삭제: let len = u16at(bytes, at + 2) as usize; | |
| 370 | 삭제: let end = at + 4 + len; | |
| 371 | 삭제: if end > bytes.len() { | |
| 372 | 삭제: return Err(ErrorCode::Integrity); | |
| 373 | 삭제: } | |
| 374 | 삭제: if tag == 1 { | |
| 375 | 삭제: if large.is_some() { | |
| 376 | 삭제: return Err(ErrorCode::Integrity); | |
| 377 | 삭제: } | |
| 378 | 삭제: large = Some(bytes[at + 4..end].to_vec()); | |
| 379 | 삭제: } else { | |
| 380 | 삭제: aes.extend_from_slice(&bytes[at..end]); | |
| 381 | 삭제: } | |
| 382 | 삭제: at = end; | |
| 383 | 삭제: } | |
| 384 | 삭제: Ok((archive::aes_extra(&aes)?, large)) | |
| 385 | 삭제: } | |
| 386 | 삭제: fn large_value(value: u32, extra: &mut &[u8]) -> Result<u64> { | |
| 387 | 삭제: if value != u32::MAX { | |
| 388 | 삭제: return Ok(value as u64); | |
| 389 | 삭제: } | |
| 390 | 삭제: if extra.len() < 8 { | |
| 391 | 삭제: return Err(ErrorCode::Integrity); | |
| 392 | 삭제: } | |
| 393 | 삭제: let result = u64at(extra, 0); | |
| 394 | 삭제: *extra = &extra[8..]; | |
| 395 | 삭제: Ok(result) | |
| 396 | 삭제: } | |
| 397 | 삭제: fn expanded(value: u64, maximum: u64, large: u64) -> Result<u64> { | |
| 398 | 삭제: if value == maximum || value == large { | |
| 399 | 삭제: Ok(large) | |
| 400 | 삭제: } else { | |
| 401 | 삭제: Err(ErrorCode::Integrity) | |
| 402 | 삭제: } | |
| 403 | 삭제: } | |
| 404 | 삭제: fn disk_start(value: u16, extra: &mut &[u8]) -> Result<u32> { | |
| 405 | 삭제: if value != u16::MAX { | |
| 406 | 삭제: return Ok(value as u32); | |
| 407 | 삭제: } | |
| 408 | 삭제: if extra.len() < 4 { | |
| 409 | 삭제: return Err(ErrorCode::Integrity); | |
| 410 | 삭제: } | |
| 411 | 삭제: let result = u32at(extra, 0); | |
| 412 | 삭제: *extra = &extra[4..]; | |
| 413 | 삭제: Ok(result) | |
| 414 | 삭제: } | |
| 415 | 삭제: fn local_sizes(size: u32, compressed: u32, extra: Option<&[u8]>) -> Result<(u64, u64)> { | |
| 416 | 삭제: if let Some(extra) = extra { | |
| 417 | 삭제: // 로컬 ZIP64 추가 필드에는 두 크기가 함께 들어감. | |
| 418 | 삭제: if extra.len() < 16 { | |
| 419 | 삭제: return Err(ErrorCode::Integrity); | |
| 420 | 삭제: } | |
| 421 | 삭제: Ok(( | |
| 422 | 삭제: expanded(size as u64, u32::MAX as u64, u64at(extra, 0))?, | |
| 423 | 삭제: expanded(compressed as u64, u32::MAX as u64, u64at(extra, 8))?, | |
| 424 | 삭제: )) | |
| 425 | 삭제: } else if size == u32::MAX || compressed == u32::MAX { | |
| 426 | 삭제: Err(ErrorCode::Integrity) | |
| 427 | 삭제: } else { | |
| 428 | 삭제: Ok((size as u64, compressed as u64)) | |
| 429 | 삭제: } | |
| 430 | 삭제: } | |
| 431 | 361 | fn descriptor_size( |
| 432 | 362 | bytes: &[u8], |
| 433 | 363 | crc: u32, |
| @@ -572,10 +502,12 @@ fn zip( | ||
| 572 | 502 | } |
| 573 | 503 | let raw = bytes(source, cursor + 46, nn as usize)?; |
| 574 | 504 | let central_extra = bytes(source, cursor + 46 + nn, ne as usize)?; |
| 575 | 삭제: let (aes, large) = extra(¢ral_extra)?; | |
| 505 | 추가: let parsed_extra = zip_extra::parse(¢ral_extra, Policy::Streaming)?; | |
| 506 | 추가: let aes = parsed_extra.aes; | |
| 507 | 추가: let large = parsed_extra.zip64; | |
| 576 | 508 | let name = archive::zip_name(&raw, flags, ¢ral_extra)?; |
| 577 | 509 | let name = name.as_str(); |
| 578 | 삭제: let mut large = large.as_deref().unwrap_or(&[]); | |
| 510 | 추가: let mut large = large.unwrap_or(&[]); | |
| 579 | 511 | let size = large_value(u32at(&h, 24), &mut large)?; |
| 580 | 512 | let compressed = large_value(u32at(&h, 20), &mut large)?; |
| 581 | 513 | let local = large_value(u32at(&h, 42), &mut large)?; |
| @@ -653,7 +585,9 @@ fn zip( | ||
| 653 | 585 | if bytes(source, local + 30, ln as usize)? != raw { |
| 654 | 586 | return Err(ErrorCode::Integrity); |
| 655 | 587 | } |
| 656 | 삭제: let (local_aes, local_large) = extra(&bytes(source, local + 30 + ln, le as usize)?)?; | |
| 588 | 추가: let local_extra = bytes(source, local + 30 + ln, le as usize)?; | |
| 589 | 추가: let parsed_local = zip_extra::parse(&local_extra, Policy::Streaming)?; | |
| 590 | 추가: let (local_aes, local_large) = (parsed_local.aes, parsed_local.zip64); | |
| 657 | 591 | if local_aes != aes || local_large.as_ref().is_some_and(|values| values.len() < 16) { |
| 658 | 592 | return Err(ErrorCode::Integrity); |
| 659 | 593 | } |
| @@ -664,7 +598,7 @@ fn zip( | ||
| 664 | 598 | || local_large.is_some(); |
| 665 | 599 | if flags & 8 == 0 { |
| 666 | 600 | let (local_size, local_compressed) = |
| 667 | 삭제: local_sizes(u32at(&lh, 22), u32at(&lh, 18), local_large.as_deref())?; | |
| 601 | 추가: local_sizes(u32at(&lh, 22), u32at(&lh, 18), local_large)?; | |
| 668 | 602 | if u32at(&lh, 14) != crc || local_size != size || local_compressed != compressed { |
| 669 | 603 | return Err(ErrorCode::Integrity); |
| 670 | 604 | } |
| @@ -0,0 +1,157 @@ | ||
| 1 | 추가: use crate::protocol::ErrorCode; | |
| 2 | 추가: | |
| 3 | 추가: type Result<T> = std::result::Result<T, ErrorCode>; | |
| 4 | 추가: | |
| 5 | 추가: #[derive(Clone, Copy, PartialEq, Eq)] | |
| 6 | 추가: pub(crate) enum Policy { | |
| 7 | 추가: Streaming, | |
| 8 | 추가: Classic, | |
| 9 | 추가: Recovery, | |
| 10 | 추가: Names, | |
| 11 | 추가: } | |
| 12 | 추가: | |
| 13 | 추가: #[derive(Clone, Copy, Debug, PartialEq, Eq)] | |
| 14 | 추가: pub(crate) struct AesExtra { | |
| 15 | 추가: pub version: u16, | |
| 16 | 추가: pub method: u16, | |
| 17 | 추가: } | |
| 18 | 추가: | |
| 19 | 추가: #[derive(Default, Debug)] | |
| 20 | 추가: pub(crate) struct Extra<'a> { | |
| 21 | 추가: pub aes: Option<AesExtra>, | |
| 22 | 추가: pub zip64: Option<&'a [u8]>, | |
| 23 | 추가: pub unicode: Option<&'a [u8]>, | |
| 24 | 추가: } | |
| 25 | 추가: | |
| 26 | 추가: fn u16at(bytes: &[u8], at: usize) -> u16 { | |
| 27 | 추가: u16::from_le_bytes(bytes[at..at + 2].try_into().unwrap()) | |
| 28 | 추가: } | |
| 29 | 추가: fn u32at(bytes: &[u8], at: usize) -> u32 { | |
| 30 | 추가: u32::from_le_bytes(bytes[at..at + 4].try_into().unwrap()) | |
| 31 | 추가: } | |
| 32 | 추가: fn u64at(bytes: &[u8], at: usize) -> u64 { | |
| 33 | 추가: u64::from_le_bytes(bytes[at..at + 8].try_into().unwrap()) | |
| 34 | 추가: } | |
| 35 | 추가: | |
| 36 | 추가: fn aes(value: &[u8]) -> Result<AesExtra> { | |
| 37 | 추가: if value.len() < 7 { | |
| 38 | 추가: return Err(ErrorCode::Integrity); | |
| 39 | 추가: } | |
| 40 | 추가: let version = u16at(value, 0); | |
| 41 | 추가: let method = u16at(value, 5); | |
| 42 | 추가: if !matches!(version, 1 | 2) | |
| 43 | 추가: || &value[2..4] != b"AE" | |
| 44 | 추가: || value[4] != 3 | |
| 45 | 추가: || !matches!(method, 0 | 8) | |
| 46 | 추가: { | |
| 47 | 추가: return Err(ErrorCode::UnsupportedFeature); | |
| 48 | 추가: } | |
| 49 | 추가: Ok(AesExtra { version, method }) | |
| 50 | 추가: } | |
| 51 | 추가: | |
| 52 | 추가: pub(crate) fn parse(bytes: &[u8], policy: Policy) -> Result<Extra<'_>> { | |
| 53 | 추가: let mut found = Extra::default(); | |
| 54 | 추가: let mut deferred_aes = None; | |
| 55 | 추가: let mut duplicate_aes = false; | |
| 56 | 추가: let mut at = 0; | |
| 57 | 추가: while at < bytes.len() { | |
| 58 | 추가: if bytes.len() - at < 4 { | |
| 59 | 추가: return Err(ErrorCode::Integrity); | |
| 60 | 추가: } | |
| 61 | 추가: let tag = u16at(bytes, at); | |
| 62 | 추가: let length = u16at(bytes, at + 2) as usize; | |
| 63 | 추가: // 복구 경로는 확장 크기와 강한 암호화를 해석하지 않음. | |
| 64 | 추가: if policy == Policy::Recovery && matches!(tag, 1 | 0x0017 | 0x0018) { | |
| 65 | 추가: return Err(ErrorCode::UnsupportedFeature); | |
| 66 | 추가: } | |
| 67 | 추가: let end = at.checked_add(4 + length).ok_or(ErrorCode::Integrity)?; | |
| 68 | 추가: let value = bytes.get(at + 4..end).ok_or(ErrorCode::Integrity)?; | |
| 69 | 추가: match (policy, tag) { | |
| 70 | 추가: (Policy::Classic, 1) => return Err(ErrorCode::UnsupportedFeature), | |
| 71 | 추가: (Policy::Streaming, 1) => { | |
| 72 | 추가: if found.zip64.replace(value).is_some() { | |
| 73 | 추가: return Err(ErrorCode::Integrity); | |
| 74 | 추가: } | |
| 75 | 추가: } | |
| 76 | 추가: (Policy::Classic, 0x9901) => { | |
| 77 | 추가: if found.aes.is_some() { | |
| 78 | 추가: return Err(ErrorCode::Integrity); | |
| 79 | 추가: } | |
| 80 | 추가: found.aes = Some(aes(value)?); | |
| 81 | 추가: } | |
| 82 | 추가: (Policy::Streaming, 0x9901) => { | |
| 83 | 추가: if deferred_aes.is_some() { | |
| 84 | 추가: duplicate_aes = true; | |
| 85 | 추가: } else { | |
| 86 | 추가: deferred_aes = Some(value); | |
| 87 | 추가: } | |
| 88 | 추가: } | |
| 89 | 추가: (Policy::Names, 0x7075) => { | |
| 90 | 추가: if found.unicode.is_some() || length < 5 { | |
| 91 | 추가: return Err(ErrorCode::Integrity); | |
| 92 | 추가: } | |
| 93 | 추가: found.unicode = Some(value); | |
| 94 | 추가: } | |
| 95 | 추가: _ => {} | |
| 96 | 추가: } | |
| 97 | 추가: at = end; | |
| 98 | 추가: } | |
| 99 | 추가: // 스트리밍은 전체 필드 경계를 확인한 뒤 AES 지원 여부를 판단함. | |
| 100 | 추가: if let Some(value) = deferred_aes { | |
| 101 | 추가: found.aes = Some(aes(value)?); | |
| 102 | 추가: if duplicate_aes { | |
| 103 | 추가: return Err(ErrorCode::Integrity); | |
| 104 | 추가: } | |
| 105 | 추가: } | |
| 106 | 추가: Ok(found) | |
| 107 | 추가: } | |
| 108 | 추가: | |
| 109 | 추가: pub(crate) fn large_value(value: u32, extra: &mut &[u8]) -> Result<u64> { | |
| 110 | 추가: if value != u32::MAX { | |
| 111 | 추가: return Ok(value as u64); | |
| 112 | 추가: } | |
| 113 | 추가: if extra.len() < 8 { | |
| 114 | 추가: return Err(ErrorCode::Integrity); | |
| 115 | 추가: } | |
| 116 | 추가: let result = u64at(extra, 0); | |
| 117 | 추가: *extra = &extra[8..]; | |
| 118 | 추가: Ok(result) | |
| 119 | 추가: } | |
| 120 | 추가: pub(crate) fn expanded(value: u64, maximum: u64, large: u64) -> Result<u64> { | |
| 121 | 추가: if value == maximum || value == large { | |
| 122 | 추가: Ok(large) | |
| 123 | 추가: } else { | |
| 124 | 추가: Err(ErrorCode::Integrity) | |
| 125 | 추가: } | |
| 126 | 추가: } | |
| 127 | 추가: pub(crate) fn disk_start(value: u16, extra: &mut &[u8]) -> Result<u32> { | |
| 128 | 추가: if value != u16::MAX { | |
| 129 | 추가: return Ok(value as u32); | |
| 130 | 추가: } | |
| 131 | 추가: if extra.len() < 4 { | |
| 132 | 추가: return Err(ErrorCode::Integrity); | |
| 133 | 추가: } | |
| 134 | 추가: let result = u32at(extra, 0); | |
| 135 | 추가: *extra = &extra[4..]; | |
| 136 | 추가: Ok(result) | |
| 137 | 추가: } | |
| 138 | 추가: pub(crate) fn local_sizes(size: u32, compressed: u32, extra: Option<&[u8]>) -> Result<(u64, u64)> { | |
| 139 | 추가: if let Some(extra) = extra { | |
| 140 | 추가: // 로컬 ZIP64 추가 필드에는 두 크기가 함께 들어감. | |
| 141 | 추가: if extra.len() < 16 { | |
| 142 | 추가: return Err(ErrorCode::Integrity); | |
| 143 | 추가: } | |
| 144 | 추가: Ok(( | |
| 145 | 추가: expanded(size as u64, u32::MAX as u64, u64at(extra, 0))?, | |
| 146 | 추가: expanded(compressed as u64, u32::MAX as u64, u64at(extra, 8))?, | |
| 147 | 추가: )) | |
| 148 | 추가: } else if size == u32::MAX || compressed == u32::MAX { | |
| 149 | 추가: Err(ErrorCode::Integrity) | |
| 150 | 추가: } else { | |
| 151 | 추가: Ok((size as u64, compressed as u64)) | |
| 152 | 추가: } | |
| 153 | 추가: } | |
| 154 | 추가: | |
| 155 | 추가: #[cfg(test)] | |
| 156 | 추가: #[path = "../../../tests/rust-archive-worker/zip_extra.rs"] | |
| 157 | 추가: mod tests; |
| @@ -38,24 +38,6 @@ fn bytes(source: &mut File, offset: u64, size: usize, end: u64) -> Result<Vec<u8 | ||
| 38 | 38 | io(source.read_exact(&mut data))?; |
| 39 | 39 | Ok(data) |
| 40 | 40 | } |
| 41 | 삭제: fn extra(data: &[u8]) -> Result<()> { | |
| 42 | 삭제: let mut at = 0; | |
| 43 | 삭제: while at < data.len() { | |
| 44 | 삭제: if data.len() - at < 4 { | |
| 45 | 삭제: return Err(ErrorCode::Integrity); | |
| 46 | 삭제: } | |
| 47 | 삭제: let tag = u16at(data, at); | |
| 48 | 삭제: let size = u16at(data, at + 2) as usize; | |
| 49 | 삭제: if matches!(tag, 1 | 0x0017 | 0x0018) { | |
| 50 | 삭제: return Err(ErrorCode::UnsupportedFeature); | |
| 51 | 삭제: } | |
| 52 | 삭제: at = at | |
| 53 | 삭제: .checked_add(4 + size) | |
| 54 | 삭제: .filter(|n| *n <= data.len()) | |
| 55 | 삭제: .ok_or(ErrorCode::Integrity)?; | |
| 56 | 삭제: } | |
| 57 | 삭제: Ok(()) | |
| 58 | 삭제: } | |
| 59 | 41 | struct Candidate { |
| 60 | 42 | finding: RecoveryEntry, |
| 61 | 43 | start: u64, |
| @@ -438,7 +420,7 @@ fn central( | ||
| 438 | 420 | charge(&mut metadata, nn, ne, check)?; |
| 439 | 421 | let raw = bytes(source, at + 46, nn, cd_end)?; |
| 440 | 422 | let ext = bytes(source, at + 46 + nn as u64, ne, cd_end)?; |
| 441 | 삭제: extra(&ext)?; | |
| 423 | 추가: crate::zip_extra::parse(&ext, crate::zip_extra::Policy::Recovery)?; | |
| 442 | 424 | let (size, packed) = declared(u32at(&h, 24), u32at(&h, 20))?; |
| 443 | 425 | let unix_kind = (u32at(&h, 38) >> 16) & 0xf000; |
| 444 | 426 | let kind = match unix_kind { |
| @@ -579,7 +561,7 @@ fn local( | ||
| 579 | 561 | } |
| 580 | 562 | let raw = bytes(source, at + 30, nn, len)?; |
| 581 | 563 | let ext = bytes(source, at + 30 + nn as u64, ne, len)?; |
| 582 | 삭제: extra(&ext)?; | |
| 564 | 추가: crate::zip_extra::parse(&ext, crate::zip_extra::Policy::Recovery)?; | |
| 583 | 565 | let kind = if raw.ends_with(b"/") { |
| 584 | 566 | EntryKind::Directory |
| 585 | 567 | } else { |
| @@ -17,6 +17,7 @@ python3 tests/ci/run_rust.py local --job rust-local | ||
| 17 | 17 | - 추적된 fixture를 Git blob과 대조합니다. Windows checkout 시 core.autocrlf=false를 사용해야 하며 기대값의 바이트를 바꾸지 않습니다. |
| 18 | 18 | - 개별 단계는 `build`, `test`, `cross-build`로 실행할 수 있습니다. 한 crate가 실패해도 다른 crate 결과를 수집합니다. |
| 19 | 19 | - GUI 앱은 컴파일하며 실제 화면 시나리오는 실행하지 않습니다. C# 시험과 역사적 hash 검사는 포함하지 않습니다. |
| 20 | 추가: - Linux 작업자의 작은 임시 공간 시험은 기본 실행에 포함합니다. 자식 프로세스에만 적용한 LD_PRELOAD 보조 코드로 2MiB 공유 용량, 부분 쓰기와 ENOSPC 및 핸들 종료 후 공간 반환을 재현합니다. 커널 tmpfs를 직접 마운트한 실기 검증은 아닙니다. | |
| 20 | 21 | |
| 21 | 22 | ## 출시 전 Windows 실기 확인 |
| 22 | 23 |
| @@ -149,7 +149,7 @@ fn empty_root_folder_is_preserved() { | ||
| 149 | 149 | let events = execute(start); |
| 150 | 150 | assert_eq!(terminal(&events).outcome, Outcome::Completed, "{events:?}"); |
| 151 | 151 | let bytes = fs::read(s.0.join("created.zip")).unwrap(); |
| 152 | 삭제: let catalog = archive::parse(&bytes, Limits::default(), true, &mut || Ok(())).unwrap(); | |
| 152 | 추가: let catalog = worker_catalog(&bytes, Limits::default(), true, None).unwrap(); | |
| 153 | 153 | assert_eq!(catalog.members.len(), 1); |
| 154 | 154 | assert_eq!(catalog.members[0].entry.kind, EntryKind::Directory); |
| 155 | 155 | assert_eq!(catalog.members[0].entry.name, "documents"); |
| @@ -828,7 +828,7 @@ fn created_empty_files_and_directories_refresh_idle_deadline() { | ||
| 828 | 828 | assert_eq!(terminal(&events).publication, Publication::Complete); |
| 829 | 829 | assert_eq!(terminal(&events).created_count, 1); |
| 830 | 830 | let bytes = fs::read(s.0.join("new.zip")).unwrap(); |
| 831 | 삭제: let parsed = archive::parse(&bytes, Limits::default(), true, &mut || Ok(())).unwrap(); | |
| 831 | 추가: let parsed = worker_catalog(&bytes, Limits::default(), true, None).unwrap(); | |
| 832 | 832 | assert_eq!(parsed.members.len(), 37); |
| 833 | 833 | assert!(parsed.members.iter().any(|member| { |
| 834 | 834 | member.entry.name == "source" && member.entry.kind == EntryKind::Directory |
| @@ -10,17 +10,21 @@ use zipelo_archive_worker::{ | ||
| 10 | 10 | protocol::*, |
| 11 | 11 | wire::{Reader, Writer}, |
| 12 | 12 | }; |
| 13 | 추가: mod real_catalog; | |
| 14 | 추가: use real_catalog::worker_catalog; | |
| 15 | 추가: | |
| 13 | 16 | static NEXT: AtomicU64 = AtomicU64::new(0); |
| 14 | 17 | struct Scratch(PathBuf); |
| 15 | 18 | impl Scratch { |
| 16 | 19 | fn new() -> Self { |
| 17 | 삭제: let path = PathBuf::from(std::env::var_os("ZIPELO_TEST_WORK_DIR").expect("runner 작업 경로 필요")) | |
| 18 | 삭제: .join("fixtures/rust-archive-worker") | |
| 19 | 삭제: .join(format!( | |
| 20 | 삭제: "{}-{}", | |
| 21 | 삭제: std::process::id(), | |
| 22 | 삭제: NEXT.fetch_add(1, Ordering::Relaxed) | |
| 23 | 삭제: )); | |
| 20 | 추가: let path = | |
| 21 | 추가: PathBuf::from(std::env::var_os("ZIPELO_TEST_WORK_DIR").expect("runner 작업 경로 필요")) | |
| 22 | 추가: .join("fixtures/rust-archive-worker") | |
| 23 | 추가: .join(format!( | |
| 24 | 추가: "{}-{}", | |
| 25 | 추가: std::process::id(), | |
| 26 | 추가: NEXT.fetch_add(1, Ordering::Relaxed) | |
| 27 | 추가: )); | |
| 24 | 28 | fs::create_dir_all(path.parent().unwrap()).unwrap(); |
| 25 | 29 | let builder = fs::DirBuilder::new(); |
| 26 | 30 | #[cfg(unix)] |
| @@ -414,7 +418,7 @@ fn create_store_and_deflate_zip() { | ||
| 414 | 418 | }); |
| 415 | 419 | assert_eq!(terminal(&e).outcome, Outcome::Completed, "{e:?}"); |
| 416 | 420 | let bytes = fs::read(s.0.join("result.zip")).unwrap(); |
| 417 | 삭제: let parsed = archive::parse(&bytes, Limits::default(), true, &mut || Ok(())).unwrap(); | |
| 421 | 추가: let parsed = worker_catalog(&bytes, Limits::default(), true, None).unwrap(); | |
| 418 | 422 | assert_eq!(parsed.members[0].data, PAYLOAD); |
| 419 | 423 | } |
| 420 | 424 | } |
| @@ -723,15 +727,7 @@ fn shallow_zip_parent_metadata_is_bounded() { | ||
| 723 | 727 | .iter() |
| 724 | 728 | .all(|n| n.split('/').count() <= archive::MAX_PATH_DEPTH) |
| 725 | 729 | ); |
| 726 | 삭제: assert!( | |
| 727 | 삭제: archive::parse( | |
| 728 | 삭제: &path_fixture_zip(&names), | |
| 729 | 삭제: Limits::default(), | |
| 730 | 삭제: false, | |
| 731 | 삭제: &mut || Ok(()) | |
| 732 | 삭제: ) | |
| 733 | 삭제: .is_ok() | |
| 734 | 삭제: ); | |
| 730 | 추가: assert!(worker_catalog(&path_fixture_zip(&names), Limits::default(), false, None).is_ok()); | |
| 735 | 731 | assert_metadata_limit(&names); |
| 736 | 732 | } |
| 737 | 733 | |
| @@ -749,7 +745,7 @@ fn aggregate_archive_name_metadata_is_bounded() { | ||
| 749 | 745 | let bytes = path_fixture_zip(&names); |
| 750 | 746 | assert!((bytes.len() as u64) < Limits::default().input); |
| 751 | 747 | assert!(matches!( |
| 752 | 삭제: archive::parse(&bytes, Limits::default(), false, &mut || Ok(())), | |
| 748 | 추가: worker_catalog(&bytes, Limits::default(), false, None), | |
| 753 | 749 | Err(ErrorCode::Limit) |
| 754 | 750 | )); |
| 755 | 751 | assert_metadata_limit(&names); |
| @@ -787,7 +783,7 @@ fn zero_payload_gzip_is_not_tar() { | ||
| 787 | 783 | for length in [512, 1024, 1536] { |
| 788 | 784 | let scratch = Scratch::new(); |
| 789 | 785 | let bytes = zeros_gzip(length); |
| 790 | 삭제: let parsed = archive::parse(&bytes, Limits::default(), true, &mut || Ok(())).unwrap(); | |
| 786 | 추가: let parsed = worker_catalog(&bytes, Limits::default(), true, None).unwrap(); | |
| 791 | 787 | assert_eq!(parsed.format, Format::Gzip); |
| 792 | 788 | let events = extract( |
| 793 | 789 | &scratch, |
| @@ -1160,14 +1156,7 @@ fn empty_aes_members_and_random_salts_round_trip() { | ||
| 1160 | 1156 | ) |
| 1161 | 1157 | .unwrap(); |
| 1162 | 1158 | assert_ne!(a, b); |
| 1163 | 삭제: let decoded = archive::parse_with_password( | |
| 1164 | 삭제: &a, | |
| 1165 | 삭제: Limits::default(), | |
| 1166 | 삭제: true, | |
| 1167 | 삭제: Some(TEST_PASSWORD), | |
| 1168 | 삭제: &mut || Ok(()), | |
| 1169 | 삭제: ) | |
| 1170 | 삭제: .unwrap(); | |
| 1159 | 추가: let decoded = worker_catalog(&a, Limits::default(), true, Some(TEST_PASSWORD)).unwrap(); | |
| 1171 | 1160 | assert!(decoded.members[0].data.is_empty()); |
| 1172 | 1161 | } |
| 1173 | 1162 | |
| @@ -1230,7 +1219,7 @@ fn seven_zip_lzma_lzma2_and_copy_interoperate() { | ||
| 1230 | 1219 | "libarchive-lzma2.7z", |
| 1231 | 1220 | ] { |
| 1232 | 1221 | let bytes = seven_fixture(name); |
| 1233 | 삭제: let catalog = archive::parse(&bytes, Limits::default(), true, &mut || Ok(())) | |
| 1222 | 추가: let catalog = worker_catalog(&bytes, Limits::default(), true, None) | |
| 1234 | 1223 | .unwrap_or_else(|e| panic!("{name}: {e:?}")); |
| 1235 | 1224 | assert_eq!(catalog.format, Format::SevenZip); |
| 1236 | 1225 | assert_eq!(catalog.members[0].data, SEVEN_PAYLOAD.repeat(100), "{name}"); |
| @@ -1251,7 +1240,7 @@ fn seven_zip_lzma_lzma2_and_copy_interoperate() { | ||
| 1251 | 1240 | fn seven_zip_encoded_header_solid_and_empty_entries() { |
| 1252 | 1241 | let s = Scratch::new(); |
| 1253 | 1242 | let bytes = seven_fixture("encoded-solid.7z"); |
| 1254 | 삭제: let catalog = archive::parse(&bytes, Limits::default(), false, &mut || Ok(())).unwrap(); | |
| 1243 | 추가: let catalog = worker_catalog(&bytes, Limits::default(), false, None).unwrap(); | |
| 1255 | 1244 | assert_eq!(catalog.members.len(), 4); |
| 1256 | 1245 | let events = extract(&s, &bytes, None, Selection::All, None, Limits::default()); |
| 1257 | 1246 | assert_eq!(terminal(&events).outcome, Outcome::Completed, "{events:?}"); |
| @@ -1268,7 +1257,7 @@ fn seven_zip_encoded_header_solid_and_empty_entries() { | ||
| 1268 | 1257 | fn seven_zip_long_matches_and_lzma2_chunks() { |
| 1269 | 1258 | for name in ["long-match.7z", "lzma2-chunks.7z"] { |
| 1270 | 1259 | let bytes = seven_fixture(name); |
| 1271 | 삭제: let catalog = archive::parse(&bytes, Limits::default(), true, &mut || Ok(())) | |
| 1260 | 추가: let catalog = worker_catalog(&bytes, Limits::default(), true, None) | |
| 1272 | 1261 | .unwrap_or_else(|e| panic!("{name}: {e:?}")); |
| 1273 | 1262 | if name == "long-match.7z" { |
| 1274 | 1263 | assert_eq!(catalog.members[0].data, SEVEN_PAYLOAD.repeat(10000)); |
| @@ -1445,20 +1434,6 @@ fn seven_zip_limits_truncation_and_existing_files_are_preserved() { | ||
| 1445 | 1434 | assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 0); |
| 1446 | 1435 | } |
| 1447 | 1436 | #[test] |
| 1448 | 삭제: fn seven_zip_parser_honors_cancellation_checkpoints() { | |
| 1449 | 삭제: let bytes = seven_fixture("long-match.7z"); | |
| 1450 | 삭제: let mut calls = 0; | |
| 1451 | 삭제: let result = archive::parse(&bytes, Limits::default(), true, &mut || { | |
| 1452 | 삭제: calls += 1; | |
| 1453 | 삭제: if calls >= 5 { | |
| 1454 | 삭제: Err(ErrorCode::None) | |
| 1455 | 삭제: } else { | |
| 1456 | 삭제: Ok(()) | |
| 1457 | 삭제: } | |
| 1458 | 삭제: }); | |
| 1459 | 삭제: assert!(matches!(result, Err(ErrorCode::None))); | |
| 1460 | 삭제: } | |
| 1461 | 삭제: #[test] | |
| 1462 | 1437 | fn pr64_malicious_corpus_is_rejected_without_writes() { |
| 1463 | 1438 | let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")) |
| 1464 | 1439 | .join("../../tests/malicious-archive-fixtures/fixtures"); |
| @@ -0,0 +1,76 @@ | ||
| 1 | 추가: use super::*; | |
| 2 | 추가: | |
| 3 | 추가: pub(super) fn worker_catalog( | |
| 4 | 추가: bytes: &[u8], | |
| 5 | 추가: limits: Limits, | |
| 6 | 추가: decode: bool, | |
| 7 | 추가: password: Option<&[u8]>, | |
| 8 | 추가: ) -> Result<archive::Catalog, ErrorCode> { | |
| 9 | 추가: let scratch = Scratch::new(); | |
| 10 | 추가: fs::write(scratch.0.join("input"), bytes).unwrap(); | |
| 11 | 추가: let events = execute(Start { | |
| 12 | 추가: action: Action::List { | |
| 13 | 추가: archive: scratch.path("input"), | |
| 14 | 추가: }, | |
| 15 | 추가: limits, | |
| 16 | 추가: }); | |
| 17 | 추가: if terminal(&events).outcome != Outcome::Completed { | |
| 18 | 추가: return Err(terminal(&events).error); | |
| 19 | 추가: } | |
| 20 | 추가: let list_id = events | |
| 21 | 추가: .iter() | |
| 22 | 추가: .find_map(|event| match event { | |
| 23 | 추가: Message::ListEnd { list_id, .. } => Some(list_id.clone()), | |
| 24 | 추가: _ => None, | |
| 25 | 추가: }) | |
| 26 | 추가: .expect("작업자의 목록 식별자가 필요함"); | |
| 27 | 추가: let entries: Vec<_> = events | |
| 28 | 추가: .into_iter() | |
| 29 | 추가: .filter_map(|event| match event { | |
| 30 | 추가: Message::Entry(entry) => Some(entry), | |
| 31 | 추가: _ => None, | |
| 32 | 추가: }) | |
| 33 | 추가: .collect(); | |
| 34 | 추가: if decode { | |
| 35 | 추가: let builder = fs::DirBuilder::new(); | |
| 36 | 추가: #[cfg(unix)] | |
| 37 | 추가: let mut builder = builder; | |
| 38 | 추가: #[cfg(unix)] | |
| 39 | 추가: { | |
| 40 | 추가: use std::os::unix::fs::DirBuilderExt; | |
| 41 | 추가: builder.mode(0o700); | |
| 42 | 추가: } | |
| 43 | 추가: builder.create(scratch.0.join("output")).unwrap(); | |
| 44 | 추가: let action = Action::Extract { | |
| 45 | 추가: archive: scratch.path("input"), | |
| 46 | 추가: destination: scratch.path("output"), | |
| 47 | 추가: selection: Selection::All, | |
| 48 | 추가: gzip_output_name: (list_id.format == Format::Gzip).then(|| entries[0].name.clone()), | |
| 49 | 추가: list_id: Some(list_id.clone()), | |
| 50 | 추가: }; | |
| 51 | 추가: let start = Start { action, limits }; | |
| 52 | 추가: let extracted = if let Some(password) = password { | |
| 53 | 추가: interactive(start, |id, _, _| password_reply(id, password)) | |
| 54 | 추가: } else { | |
| 55 | 추가: execute(start) | |
| 56 | 추가: }; | |
| 57 | 추가: if terminal(&extracted).outcome != Outcome::Completed { | |
| 58 | 추가: return Err(terminal(&extracted).error); | |
| 59 | 추가: } | |
| 60 | 추가: } | |
| 61 | 추가: let members = entries | |
| 62 | 추가: .into_iter() | |
| 63 | 추가: .map(|entry| { | |
| 64 | 추가: let data = if decode && entry.kind == EntryKind::File { | |
| 65 | 추가: fs::read(scratch.0.join("output").join(&entry.name)).unwrap() | |
| 66 | 추가: } else { | |
| 67 | 추가: Vec::new() | |
| 68 | 추가: }; | |
| 69 | 추가: archive::Member { entry, data } | |
| 70 | 추가: }) | |
| 71 | 추가: .collect(); | |
| 72 | 추가: Ok(archive::Catalog { | |
| 73 | 추가: format: list_id.format, | |
| 74 | 추가: members, | |
| 75 | 추가: }) | |
| 76 | 추가: } |
| @@ -141,7 +141,7 @@ fn six_damaged_corpora_preserve_source_and_independent_expected_hashes() { | ||
| 141 | 141 | assert_eq!(t.created_count, 1); |
| 142 | 142 | assert_eq!(t.publication, Publication::Complete); |
| 143 | 143 | let bytes = fs::read(s.0.join("recovered.zip")).unwrap(); |
| 144 | 삭제: let catalog = archive::parse(&bytes, Limits::default(), true, &mut || Ok(())).unwrap(); | |
| 144 | 추가: let catalog = worker_catalog(&bytes, Limits::default(), true, None).unwrap(); | |
| 145 | 145 | assert_eq!(catalog.members.len(), count); |
| 146 | 146 | for member in &catalog.members { |
| 147 | 147 | let (_, sha) = expected |
| @@ -410,3 +410,33 @@ fn central_zip64_fields_and_extra_remain_unsupported() { | ||
| 410 | 410 | Err(ErrorCode::UnsupportedFeature) |
| 411 | 411 | )); |
| 412 | 412 | } |
| 413 | 추가: | |
| 414 | 추가: #[test] | |
| 415 | 추가: fn central_rejects_extra_crossing_only_the_next_local_file() { | |
| 416 | 추가: let mut damaged = include_bytes!("../zip-recovery-fixtures/control.zip").to_vec(); | |
| 417 | 추가: let cd = u32at(&damaged, damaged.len() - 6) as usize; | |
| 418 | 추가: let second = cd | |
| 419 | 추가: + 46 | |
| 420 | 추가: + u16at(&damaged, cd + 28) as usize | |
| 421 | 추가: + u16at(&damaged, cd + 30) as usize | |
| 422 | 추가: + u16at(&damaged, cd + 32) as usize; | |
| 423 | 추가: let next_local = u32at(&damaged, second + 42) as usize; | |
| 424 | 추가: let names_end = 30 + u16at(&damaged, 26) as usize; | |
| 425 | 추가: let extra = next_local - names_end + 1; | |
| 426 | 추가: let data_start = names_end + extra; | |
| 427 | 추가: assert!(data_start > next_local); | |
| 428 | 추가: assert!(data_start + u32at(&damaged, cd + 20) as usize <= cd); | |
| 429 | 추가: damaged[28..30].copy_from_slice(&(extra as u16).to_le_bytes()); | |
| 430 | 추가: let scratch = Scratch::new(&damaged); | |
| 431 | 추가: let mut source = File::open(scratch.path()).unwrap(); | |
| 432 | 추가: assert!(matches!( | |
| 433 | 추가: central( | |
| 434 | 추가: &mut source, | |
| 435 | 추가: damaged.len() as u64, | |
| 436 | 추가: Limits::default(), | |
| 437 | 추가: &mut || Ok(()) | |
| 438 | 추가: ), | |
| 439 | 추가: Err(ErrorCode::Integrity) | |
| 440 | 추가: )); | |
| 441 | 추가: assert_eq!(std::fs::read(scratch.path()).unwrap(), damaged); | |
| 442 | 추가: } |
| @@ -59,19 +59,31 @@ impl Case { | ||
| 59 | 59 | self.archive_names.sort(); |
| 60 | 60 | (self.scratch.path("archive/split.7z.001"), originals) |
| 61 | 61 | } |
| 62 | 추가: fn library(&self) -> PathBuf { | |
| 63 | 추가: let library = self.scratch.0.join("location.so"); | |
| 64 | 추가: if !library.exists() { | |
| 65 | 추가: assert!( | |
| 66 | 추가: Command::new("cc") | |
| 67 | 추가: .args(["-shared", "-fPIC", "-O2", "-Wall", "-Wextra", "-Werror"]) | |
| 68 | 추가: .arg( | |
| 69 | 추가: PathBuf::from(env!("CARGO_MANIFEST_DIR")) | |
| 70 | 추가: .join("../../tests/rust-archive-worker/spool_location_fault.c") | |
| 71 | 추가: ) | |
| 72 | 추가: .args(["-ldl", "-o"]) | |
| 73 | 추가: .arg(&library) | |
| 74 | 추가: .status() | |
| 75 | 추가: .unwrap() | |
| 76 | 추가: .success() | |
| 77 | 추가: ); | |
| 78 | 추가: } | |
| 79 | 추가: library | |
| 80 | 추가: } | |
| 62 | 81 | fn run(&self, action: Action, phase: &str, mask: u8, named: bool) -> Vec<Message> { |
| 63 | 82 | let s = &self.scratch; |
| 64 | 83 | let mut command = s.worker(); |
| 65 | 84 | command |
| 66 | 85 | .env("XDG_CACHE_HOME", s.0.join("cache")) |
| 67 | 삭제: .env( | |
| 68 | 삭제: "TMPDIR", | |
| 69 | 삭제: if phase == "real" { | |
| 70 | 삭제: PathBuf::from(std::env::var_os("ZIPELO_SPOOL_REAL_TMP").unwrap()) | |
| 71 | 삭제: } else { | |
| 72 | 삭제: s.0.join("system") | |
| 73 | 삭제: }, | |
| 74 | 삭제: ) | |
| 86 | 추가: .env("TMPDIR", s.0.join("system")) | |
| 75 | 87 | .env("HOME", &s.0); |
| 76 | 88 | if phase == "home" { |
| 77 | 89 | command.env_remove("XDG_CACHE_HOME"); |
| @@ -87,31 +99,14 @@ impl Case { | ||
| 87 | 99 | }, |
| 88 | 100 | ); |
| 89 | 101 | } |
| 90 | 삭제: if phase != "real" { | |
| 91 | 삭제: let library = s.0.join("location.so"); | |
| 92 | 삭제: if !library.exists() { | |
| 93 | 삭제: assert!( | |
| 94 | 삭제: Command::new("cc") | |
| 95 | 삭제: .args(["-shared", "-fPIC", "-O2", "-Wall", "-Wextra", "-Werror"]) | |
| 96 | 삭제: .arg( | |
| 97 | 삭제: PathBuf::from(env!("CARGO_MANIFEST_DIR")) | |
| 98 | 삭제: .join("../../tests/rust-archive-worker/spool_location_fault.c") | |
| 99 | 삭제: ) | |
| 100 | 삭제: .args(["-ldl", "-o"]) | |
| 101 | 삭제: .arg(&library) | |
| 102 | 삭제: .status() | |
| 103 | 삭제: .unwrap() | |
| 104 | 삭제: .success() | |
| 105 | 삭제: ); | |
| 106 | 삭제: } | |
| 107 | 삭제: command | |
| 108 | 삭제: .env("LD_PRELOAD", library) | |
| 109 | 삭제: .env("ZIPELO_SPOOL_PHASE", phase) | |
| 110 | 삭제: .env("ZIPELO_SPOOL_MASK", mask.to_string()) | |
| 111 | 삭제: .env("ZIPELO_SPOOL_TRACE", s.0.join("trace")); | |
| 112 | 삭제: if named { | |
| 113 | 삭제: command.env("ZIPELO_SPOOL_NAMED", "1"); | |
| 114 | 삭제: } | |
| 102 | 추가: let library = self.library(); | |
| 103 | 추가: command | |
| 104 | 추가: .env("LD_PRELOAD", library) | |
| 105 | 추가: .env("ZIPELO_SPOOL_PHASE", phase) | |
| 106 | 추가: .env("ZIPELO_SPOOL_MASK", mask.to_string()) | |
| 107 | 추가: .env("ZIPELO_SPOOL_TRACE", s.0.join("trace")); | |
| 108 | 추가: if named { | |
| 109 | 추가: command.env("ZIPELO_SPOOL_NAMED", "1"); | |
| 115 | 110 | } |
| 116 | 111 | let mut child = Running( |
| 117 | 112 | command |
| @@ -689,45 +684,80 @@ fn source_change_during_direct_read_prevents_success() { | ||
| 689 | 684 | } |
| 690 | 685 | |
| 691 | 686 | #[test] |
| 692 | 삭제: #[ignore = "별도 VM의 작은 tmpfs 경로를 ZIPELO_SPOOL_REAL_TMP로 지정해야 함"] | |
| 693 | 삭제: fn actual_tmpfs_quota_lists_and_previews_large_zip_and_seven_zip() { | |
| 694 | 삭제: let path = PathBuf::from(std::env::var_os("ZIPELO_SPOOL_REAL_TMP").unwrap()); | |
| 695 | 삭제: let filesystem = Command::new("stat") | |
| 696 | 삭제: .args(["-f", "-c", "%T"]) | |
| 697 | 삭제: .arg(&path) | |
| 698 | 삭제: .output() | |
| 699 | 삭제: .unwrap(); | |
| 700 | 삭제: assert_eq!( | |
| 701 | 삭제: String::from_utf8(filesystem.stdout).unwrap().trim(), | |
| 702 | 삭제: "tmpfs" | |
| 703 | 삭제: ); | |
| 704 | 삭제: let capacity = Command::new("stat") | |
| 705 | 삭제: .args(["-f", "-c", "%S %b"]) | |
| 706 | 삭제: .arg(&path) | |
| 707 | 삭제: .output() | |
| 708 | 삭제: .unwrap(); | |
| 709 | 삭제: let fields: Vec<u64> = String::from_utf8(capacity.stdout) | |
| 710 | 삭제: .unwrap() | |
| 711 | 삭제: .split_whitespace() | |
| 712 | 삭제: .map(|value| value.parse().unwrap()) | |
| 713 | 삭제: .collect(); | |
| 714 | 삭제: let bytes = fields[0] * fields[1]; | |
| 715 | 삭제: assert!(bytes > 0 && bytes < 16 * 1024 * 1024, "{bytes}"); | |
| 716 | 삭제: let probe = path.join("capacity-probe"); | |
| 717 | 삭제: let error = fs::write(&probe, vec![0; bytes as usize + 4096]).unwrap_err(); | |
| 718 | 삭제: assert_eq!(error.kind(), std::io::ErrorKind::StorageFull); | |
| 719 | 삭제: fs::remove_file(probe).unwrap(); | |
| 720 | 삭제: let c = Case::new(); | |
| 721 | 삭제: for format in ["zip", "7z"] { | |
| 722 | 삭제: c.assert_preview(format, "real", 0, false); | |
| 687 | 추가: fn small_temporary_quota_lists_and_previews_large_zip_and_seven_zip() { | |
| 688 | 추가: for named in [false, true] { | |
| 689 | 추가: let c = Case::new(); | |
| 690 | 추가: let library = c.library(); | |
| 691 | 추가: let probe = Command::new("python3") | |
| 692 | 추가: .arg("-B") | |
| 693 | 추가: .arg("-c") | |
| 694 | 추가: .arg( | |
| 695 | 추가: r#" | |
| 696 | 추가: import errno, os, sys | |
| 697 | 추가: from pathlib import Path | |
| 698 | 추가: root = Path(sys.argv[1]) | |
| 699 | 추가: a = os.open(root / "quota-a", os.O_CREAT | os.O_RDWR, 0o600) | |
| 700 | 추가: b = os.open(root / "quota-b", os.O_CREAT | os.O_RDWR, 0o600) | |
| 701 | 추가: duplicate = os.dup(a) | |
| 702 | 추가: try: | |
| 703 | 추가: assert os.write(a, bytes(1024 * 1024)) == 1024 * 1024 | |
| 704 | 추가: assert os.write(b, bytes(2 * 1024 * 1024)) == 1024 * 1024 | |
| 705 | 추가: try: | |
| 706 | 추가: os.write(b, b"x") | |
| 707 | 추가: except OSError as error: | |
| 708 | 추가: assert error.errno == errno.ENOSPC | |
| 709 | 추가: else: | |
| 710 | 추가: raise AssertionError("공유 임시 용량 한도가 적용되지 않음") | |
| 711 | 추가: os.close(duplicate) | |
| 712 | 추가: duplicate = -1 | |
| 713 | 추가: os.close(a) | |
| 714 | 추가: a = -1 | |
| 715 | 추가: (root / "quota-a").unlink() | |
| 716 | 추가: assert os.write(b, b"x") == 1 | |
| 717 | 추가: finally: | |
| 718 | 추가: if duplicate >= 0: | |
| 719 | 추가: os.close(duplicate) | |
| 720 | 추가: if a >= 0: | |
| 721 | 추가: os.close(a) | |
| 722 | 추가: os.close(b) | |
| 723 | 추가: for name in ["quota-a", "quota-b"]: | |
| 724 | 추가: (root / name).unlink(missing_ok=True) | |
| 725 | 추가: "#, | |
| 726 | 추가: ) | |
| 727 | 추가: .arg(c.scratch.0.join("system")) | |
| 728 | 추가: .env("LD_PRELOAD", library) | |
| 729 | 추가: .env("ZIPELO_SPOOL_PHASE", "tiny-tmpfs") | |
| 730 | 추가: .env("ZIPELO_SPOOL_TRACE", c.scratch.0.join("trace")) | |
| 731 | 추가: .output() | |
| 732 | 추가: .unwrap(); | |
| 733 | 추가: assert!(probe.status.success(), "{:?}", probe.stderr); | |
| 734 | 추가: assert!( | |
| 735 | 추가: fs::read_to_string(c.scratch.0.join("trace")) | |
| 736 | 추가: .unwrap() | |
| 737 | 추가: .contains('F') | |
| 738 | 추가: ); | |
| 739 | 추가: for format in ["zip", "7z"] { | |
| 740 | 추가: c.assert_preview(format, "tiny-tmpfs", 0, named); | |
| 741 | 추가: } | |
| 742 | 추가: assert!( | |
| 743 | 추가: Command::new("python3") | |
| 744 | 추가: .arg("-B") | |
| 745 | 추가: .arg( | |
| 746 | 추가: PathBuf::from(env!("CARGO_MANIFEST_DIR")) | |
| 747 | 추가: .join("../../tests/rust-archive-worker/spool_fallback_cases.py") | |
| 748 | 추가: ) | |
| 749 | 추가: .arg(&c.scratch.0) | |
| 750 | 추가: .arg("non-solid") | |
| 751 | 추가: .status() | |
| 752 | 추가: .unwrap() | |
| 753 | 추가: .success() | |
| 754 | 추가: ); | |
| 755 | 추가: for format in ["zip", "7z"] { | |
| 756 | 추가: c.assert_preview(format, "tiny-tmpfs", 3, named); | |
| 757 | 추가: } | |
| 758 | 추가: let trace = fs::read_to_string(c.scratch.0.join("trace")).unwrap(); | |
| 759 | 추가: assert!(trace.contains('2'), "{trace}"); | |
| 760 | 추가: assert_eq!(fs::read_dir(c.scratch.0.join("system")).unwrap().count(), 0); | |
| 761 | 추가: c.clean(); | |
| 723 | 762 | } |
| 724 | 삭제: assert_eq!(fs::read_dir(path).unwrap().count(), 0); | |
| 725 | 삭제: assert_eq!( | |
| 726 | 삭제: fs::metadata(c.scratch.0.join("cache/zipelo")) | |
| 727 | 삭제: .unwrap() | |
| 728 | 삭제: .permissions() | |
| 729 | 삭제: .mode() | |
| 730 | 삭제: & 0o777, | |
| 731 | 삭제: 0o700 | |
| 732 | 삭제: ); | |
| 733 | 763 | } |
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | #define _GNU_SOURCE |
| 2 | 2 | #include <dlfcn.h> |
| 3 | 추가: #include <dirent.h> | |
| 3 | 4 | #include <errno.h> |
| 4 | 5 | #include <fcntl.h> |
| 5 | 6 | #include <stdarg.h> |
| @@ -60,10 +61,50 @@ static void trace(int at) { | ||
| 60 | 61 | close(fd); |
| 61 | 62 | } |
| 62 | 63 | } |
| 64 | 추가: static unsigned long long temporary_usage(void) { | |
| 65 | 추가: DIR *directory = opendir("/proc/self/fd"); | |
| 66 | 추가: if (!directory) _exit(98); | |
| 67 | 추가: struct dirent *entry; | |
| 68 | 추가: struct stat seen[256]; | |
| 69 | 추가: size_t count = 0; | |
| 70 | 추가: unsigned long long used = 0; | |
| 71 | 추가: while ((entry = readdir(directory))) { | |
| 72 | 추가: if (entry->d_name[0] == '.') continue; | |
| 73 | 추가: int fd = atoi(entry->d_name); | |
| 74 | 추가: char path[4096]; | |
| 75 | 추가: struct stat value; | |
| 76 | 추가: if (descriptor(fd, path, sizeof(path)) != 2 || fstat(fd, &value) | |
| 77 | 추가: || !S_ISREG(value.st_mode)) continue; | |
| 78 | 추가: size_t i; | |
| 79 | 추가: for (i = 0; i < count; i++) { | |
| 80 | 추가: if (seen[i].st_dev == value.st_dev && seen[i].st_ino == value.st_ino) break; | |
| 81 | 추가: } | |
| 82 | 추가: if (i < count) continue; | |
| 83 | 추가: if (count == 256) _exit(97); | |
| 84 | 추가: seen[count++] = value; | |
| 85 | 추가: used += value.st_size; | |
| 86 | 추가: } | |
| 87 | 추가: closedir(directory); | |
| 88 | 추가: return used; | |
| 89 | 추가: } | |
| 90 | 추가: static void exhausted(void) { | |
| 91 | 추가: const char *path = getenv("ZIPELO_SPOOL_TRACE"); | |
| 92 | 추가: if (!path) return; | |
| 93 | 추가: int fd = original_openat(AT_FDCWD, path, O_CREAT | O_WRONLY | O_APPEND, 0600); | |
| 94 | 추가: if (fd >= 0) { | |
| 95 | 추가: original_write(fd, "F", 1); | |
| 96 | 추가: close(fd); | |
| 97 | 추가: } | |
| 98 | 추가: } | |
| 99 | 추가: #define TEMPORARY_CAPACITY (2ULL * 1024 * 1024) | |
| 63 | 100 | static int reject(int at, int flags) { |
| 64 | 101 | if ((flags & O_TMPFILE) != O_TMPFILE && !(flags & O_CREAT)) return 0; |
| 65 | 102 | trace(at); |
| 66 | 103 | const char *phase = getenv("ZIPELO_SPOOL_PHASE"); |
| 104 | 추가: if (affected(at) && at < 2 && phase && !strcmp(phase, "tiny-tmpfs")) { | |
| 105 | 추가: errno = EDQUOT; | |
| 106 | 추가: return 1; | |
| 107 | 추가: } | |
| 67 | 108 | if (affected(at) && phase && (!strcmp(phase, "create") || !strcmp(phase, "denied"))) { |
| 68 | 109 | errno = !strcmp(phase, "denied") ? EACCES : EDQUOT; |
| 69 | 110 | return 1; |
| @@ -115,6 +156,20 @@ ssize_t write(int fd, const void *bytes, size_t count) { | ||
| 115 | 156 | char path[4096]; |
| 116 | 157 | int at = descriptor(fd, path, sizeof(path)); |
| 117 | 158 | const char *phase = getenv("ZIPELO_SPOOL_PHASE"); |
| 159 | 추가: if (phase && !strcmp(phase, "tiny-tmpfs") && at == 2) { | |
| 160 | 추가: struct stat value; | |
| 161 | 추가: off_t position = lseek(fd, 0, SEEK_CUR); | |
| 162 | 추가: if (position < 0 || fstat(fd, &value)) _exit(96); | |
| 163 | 추가: unsigned long long used = temporary_usage(); | |
| 164 | 추가: unsigned long long room = used < TEMPORARY_CAPACITY ? TEMPORARY_CAPACITY - used : 0; | |
| 165 | 추가: unsigned long long end = (unsigned long long)value.st_size + room; | |
| 166 | 추가: if ((unsigned long long)position >= end) { | |
| 167 | 추가: exhausted(); | |
| 168 | 추가: errno = ENOSPC; | |
| 169 | 추가: return -1; | |
| 170 | 추가: } | |
| 171 | 추가: if (count > end - position) count = end - position; | |
| 172 | 추가: } | |
| 118 | 173 | int stage = phase && !strcmp(phase, "stage-write") && fd != snapshot_fd; |
| 119 | 174 | if (affected(at) && phase && (stage || !strcmp(phase, "write") |
| 120 | 175 | || !strcmp(phase, "changed") || !strcmp(phase, "io"))) { |
| @@ -140,6 +195,12 @@ int fstatvfs(int fd, struct statvfs *value) { | ||
| 140 | 195 | value->f_frsize = 1; |
| 141 | 196 | value->f_bavail = 65536; |
| 142 | 197 | } |
| 198 | 추가: if (!result && at == 2 && phase && !strcmp(phase, "tiny-tmpfs")) { | |
| 199 | 추가: unsigned long long used = temporary_usage(); | |
| 200 | 추가: value->f_frsize = 1; | |
| 201 | 추가: value->f_blocks = TEMPORARY_CAPACITY; | |
| 202 | 추가: value->f_bavail = value->f_bfree = used < TEMPORARY_CAPACITY ? TEMPORARY_CAPACITY - used : 0; | |
| 203 | 추가: } | |
| 143 | 204 | return result; |
| 144 | 205 | } |
| 145 | 206 |
| @@ -122,3 +122,27 @@ fn descriptor_width_uses_sizes_and_crc() { | ||
| 122 | 122 | ); |
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 추가: | |
| 126 | 추가: #[test] | |
| 127 | 추가: fn seven_zip_parser_honors_cancellation_checkpoints() { | |
| 128 | 추가: let bytes = include_bytes!("fixtures/7z/long-match.7z"); | |
| 129 | 추가: let mut source = spool::temporary().unwrap(); | |
| 130 | 추가: source.write_all(bytes).unwrap(); | |
| 131 | 추가: let mut calls = 0; | |
| 132 | 추가: let result = Catalog::open( | |
| 133 | 추가: &mut source, | |
| 134 | 추가: bytes.len() as u64, | |
| 135 | 추가: Limits::default(), | |
| 136 | 추가: true, | |
| 137 | 추가: None, | |
| 138 | 추가: &mut || { | |
| 139 | 추가: calls += 1; | |
| 140 | 추가: if calls >= 5 { | |
| 141 | 추가: Err(ErrorCode::None) | |
| 142 | 추가: } else { | |
| 143 | 추가: Ok(()) | |
| 144 | 추가: } | |
| 145 | 추가: }, | |
| 146 | 추가: ); | |
| 147 | 추가: assert!(matches!(result, Err(ErrorCode::None))); | |
| 148 | 추가: } |
| @@ -0,0 +1,129 @@ | ||
| 1 | 추가: use super::*; | |
| 2 | 추가: | |
| 3 | 추가: fn field(tag: u16, value: &[u8]) -> Vec<u8> { | |
| 4 | 추가: [ | |
| 5 | 추가: tag.to_le_bytes().as_slice(), | |
| 6 | 추가: &(value.len() as u16).to_le_bytes(), | |
| 7 | 추가: value, | |
| 8 | 추가: ] | |
| 9 | 추가: .concat() | |
| 10 | 추가: } | |
| 11 | 추가: | |
| 12 | 추가: #[test] | |
| 13 | 추가: fn truncated_headers_and_values_are_rejected_by_every_policy() { | |
| 14 | 추가: for policy in [ | |
| 15 | 추가: Policy::Streaming, | |
| 16 | 추가: Policy::Classic, | |
| 17 | 추가: Policy::Recovery, | |
| 18 | 추가: Policy::Names, | |
| 19 | 추가: ] { | |
| 20 | 추가: for bytes in [vec![0], vec![0, 0], vec![0, 0, 0], vec![2, 0, 1, 0]] { | |
| 21 | 추가: assert!(matches!(parse(&bytes, policy), Err(ErrorCode::Integrity))); | |
| 22 | 추가: } | |
| 23 | 추가: assert!(parse(&field(2, &[]), policy).is_ok()); | |
| 24 | 추가: } | |
| 25 | 추가: } | |
| 26 | 추가: | |
| 27 | 추가: #[test] | |
| 28 | 추가: fn zip64_is_borrowed_only_for_normal_streaming() { | |
| 29 | 추가: let bytes = field(1, &[0; 16]); | |
| 30 | 추가: assert_eq!( | |
| 31 | 추가: parse(&bytes, Policy::Streaming).unwrap().zip64, | |
| 32 | 추가: Some(&bytes[4..]) | |
| 33 | 추가: ); | |
| 34 | 추가: for policy in [Policy::Classic, Policy::Recovery] { | |
| 35 | 추가: assert!(matches!( | |
| 36 | 추가: parse(&bytes, policy), | |
| 37 | 추가: Err(ErrorCode::UnsupportedFeature) | |
| 38 | 추가: )); | |
| 39 | 추가: } | |
| 40 | 추가: assert!(matches!( | |
| 41 | 추가: parse( | |
| 42 | 추가: &[bytes.as_slice(), bytes.as_slice()].concat(), | |
| 43 | 추가: Policy::Streaming | |
| 44 | 추가: ), | |
| 45 | 추가: Err(ErrorCode::Integrity) | |
| 46 | 추가: )); | |
| 47 | 추가: for tag in [1, 0x0017, 0x0018] { | |
| 48 | 추가: assert!(matches!( | |
| 49 | 추가: parse(&field(tag, &[]), Policy::Recovery), | |
| 50 | 추가: Err(ErrorCode::UnsupportedFeature) | |
| 51 | 추가: )); | |
| 52 | 추가: } | |
| 53 | 추가: } | |
| 54 | 추가: | |
| 55 | 추가: #[test] | |
| 56 | 추가: fn aes_policy_keeps_support_and_duplicate_checks() { | |
| 57 | 추가: let value = [2, 0, b'A', b'E', 3, 8, 0]; | |
| 58 | 추가: let bytes = field(0x9901, &value); | |
| 59 | 추가: for policy in [Policy::Streaming, Policy::Classic] { | |
| 60 | 추가: assert_eq!( | |
| 61 | 추가: parse(&bytes, policy).unwrap().aes, | |
| 62 | 추가: Some(AesExtra { | |
| 63 | 추가: version: 2, | |
| 64 | 추가: method: 8 | |
| 65 | 추가: }) | |
| 66 | 추가: ); | |
| 67 | 추가: assert!(matches!( | |
| 68 | 추가: parse(&[bytes.as_slice(), bytes.as_slice()].concat(), policy), | |
| 69 | 추가: Err(ErrorCode::Integrity) | |
| 70 | 추가: )); | |
| 71 | 추가: assert!(matches!( | |
| 72 | 추가: parse(&field(0x9901, &value[..6]), policy), | |
| 73 | 추가: Err(ErrorCode::Integrity) | |
| 74 | 추가: )); | |
| 75 | 추가: let mut unsupported = value; | |
| 76 | 추가: unsupported[4] = 2; | |
| 77 | 추가: assert!(matches!( | |
| 78 | 추가: parse(&field(0x9901, &unsupported), policy), | |
| 79 | 추가: Err(ErrorCode::UnsupportedFeature) | |
| 80 | 추가: )); | |
| 81 | 추가: } | |
| 82 | 추가: assert!(parse(&bytes, Policy::Recovery).unwrap().aes.is_none()); | |
| 83 | 추가: } | |
| 84 | 추가: | |
| 85 | 추가: #[test] | |
| 86 | 추가: fn unicode_and_aes_fields_can_share_the_same_extra() { | |
| 87 | 추가: let bytes = [ | |
| 88 | 추가: field(0x7075, &[1, 0, 0, 0, 0]), | |
| 89 | 추가: field(0x9901, &[2, 0, b'A', b'E', 3, 0, 0]), | |
| 90 | 추가: ] | |
| 91 | 추가: .concat(); | |
| 92 | 추가: assert_eq!( | |
| 93 | 추가: parse(&bytes, Policy::Names).unwrap().unicode, | |
| 94 | 추가: Some(&bytes[4..9]) | |
| 95 | 추가: ); | |
| 96 | 추가: assert!(parse(&bytes, Policy::Streaming).unwrap().aes.is_some()); | |
| 97 | 추가: assert!(matches!( | |
| 98 | 추가: parse(&field(0x7075, &[0; 4]), Policy::Names), | |
| 99 | 추가: Err(ErrorCode::Integrity) | |
| 100 | 추가: )); | |
| 101 | 추가: } | |
| 102 | 추가: | |
| 103 | 추가: #[test] | |
| 104 | 추가: fn mixed_invalid_fields_keep_error_precedence() { | |
| 105 | 추가: let unsupported_aes = field(0x9901, &[3, 0, b'A', b'E', 3, 0, 0]); | |
| 106 | 추가: let duplicate_zip64 = [field(1, &[]), field(1, &[])].concat(); | |
| 107 | 추가: let extra = [unsupported_aes.as_slice(), duplicate_zip64.as_slice()].concat(); | |
| 108 | 추가: assert!(matches!( | |
| 109 | 추가: parse(&extra, Policy::Streaming), | |
| 110 | 추가: Err(ErrorCode::Integrity) | |
| 111 | 추가: )); | |
| 112 | 추가: assert!(matches!( | |
| 113 | 추가: parse(&extra, Policy::Classic), | |
| 114 | 추가: Err(ErrorCode::UnsupportedFeature) | |
| 115 | 추가: )); | |
| 116 | 추가: let truncated = [unsupported_aes.as_slice(), &[2, 0, 1, 0]].concat(); | |
| 117 | 추가: assert!(matches!( | |
| 118 | 추가: parse(&truncated, Policy::Streaming), | |
| 119 | 추가: Err(ErrorCode::Integrity) | |
| 120 | 추가: )); | |
| 121 | 추가: assert!(matches!( | |
| 122 | 추가: parse(&truncated, Policy::Classic), | |
| 123 | 추가: Err(ErrorCode::UnsupportedFeature) | |
| 124 | 추가: )); | |
| 125 | 추가: assert!(matches!( | |
| 126 | 추가: parse(&[1, 0, 8, 0], Policy::Recovery), | |
| 127 | 추가: Err(ErrorCode::UnsupportedFeature) | |
| 128 | 추가: )); | |
| 129 | 추가: } |
| @@ -107,20 +107,11 @@ fn listed_names(bytes: &[u8]) -> std::result::Result<Vec<String>, ErrorCode> { | ||
| 107 | 107 | .collect()) |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 삭제: /// 스트리밍 목록과 메모리 파서가 같은 이름 또는 같은 오류를 내는지 확인함. | |
| 111 | 삭제: fn names_agree(bytes: &[u8]) -> std::result::Result<Vec<String>, ErrorCode> { | |
| 112 | 삭제: let streamed = listed_names(bytes); | |
| 113 | 삭제: let parsed = archive::parse(bytes, Limits::default(), false, &mut || Ok(())) | |
| 114 | 삭제: .map(|c| c.members.into_iter().map(|m| m.entry.name).collect()); | |
| 115 | 삭제: assert_eq!(streamed, parsed); | |
| 116 | 삭제: streamed | |
| 117 | 삭제: } | |
| 118 | 삭제: | |
| 119 | 110 | #[test] |
| 120 | 111 | fn infozip_utf8_names_without_flag_list_and_extract() { |
| 121 | 삭제: assert_eq!(names_agree(KOREAN).unwrap(), ["README.md", "회의록.txt"]); | |
| 112 | 추가: assert_eq!(listed_names(KOREAN).unwrap(), ["README.md", "회의록.txt"]); | |
| 122 | 113 | assert_eq!( |
| 123 | 삭제: names_agree(KOREAN_TREE).unwrap(), | |
| 114 | 추가: listed_names(KOREAN_TREE).unwrap(), | |
| 124 | 115 | ["README.md", "회의록.txt", "폴더", "폴더/메모.txt"] |
| 125 | 116 | ); |
| 126 | 117 | for bytes in [KOREAN, KOREAN_TREE] { |
| @@ -149,7 +140,7 @@ fn infozip_multi_entry_zipcrypto_trees_list_and_extract() { | ||
| 149 | 140 | (ZIPCRYPTO_ASCII_TREE, "docs/notes.txt"), |
| 150 | 141 | (ZIPCRYPTO_KOREAN_TREE, "폴더/메모.txt"), |
| 151 | 142 | ] { |
| 152 | 삭제: let names = names_agree(bytes).unwrap(); | |
| 143 | 추가: let names = listed_names(bytes).unwrap(); | |
| 153 | 144 | assert!(names.iter().any(|n| n == file), "{names:?}"); |
| 154 | 145 | let s = Scratch::new(); |
| 155 | 146 | let events = interactive(encrypted_start(&s, bytes), |id, _, purpose| { |
| @@ -168,7 +159,7 @@ fn unicode_path_extra_is_used_only_when_its_crc_matches() { | ||
| 168 | 159 | let cp949 = b"\xc8\xb8\xc0\xc7\xb7\xcf.txt"; |
| 169 | 160 | let extra = unicode_path(cp949, "회의록.txt"); |
| 170 | 161 | assert_eq!( |
| 171 | 삭제: names_agree(&single_entry_zip(cp949, 0, &extra, b"hi\n")).unwrap(), | |
| 162 | 추가: listed_names(&single_entry_zip(cp949, 0, &extra, b"hi\n")).unwrap(), | |
| 172 | 163 | ["회의록.txt"] |
| 173 | 164 | ); |
| 174 | 165 | let s = Scratch::new(); |
| @@ -180,24 +171,24 @@ fn unicode_path_extra_is_used_only_when_its_crc_matches() { | ||
| 180 | 171 | // CRC가 다른 확장 필드는 이름이 바뀐 뒤 남은 낡은 값이므로 무시함. |
| 181 | 172 | let stale = unicode_path(b"old.txt", "회의록.txt"); |
| 182 | 173 | assert_eq!( |
| 183 | 삭제: names_agree(&single_entry_zip(b"new.txt", 0, &stale, b"hi\n")).unwrap(), | |
| 174 | 추가: listed_names(&single_entry_zip(b"new.txt", 0, &stale, b"hi\n")).unwrap(), | |
| 184 | 175 | ["new.txt"] |
| 185 | 176 | ); |
| 186 | 177 | let stale = unicode_path(b"other", "회의록.txt"); |
| 187 | 178 | assert_eq!( |
| 188 | 삭제: names_agree(&single_entry_zip(cp949, 0, &stale, b"hi\n")), | |
| 179 | 추가: listed_names(&single_entry_zip(cp949, 0, &stale, b"hi\n")), | |
| 189 | 180 | Err(ErrorCode::UnsupportedFeature) |
| 190 | 181 | ); |
| 191 | 182 | // UTF-8 플래그가 있으면 이름 자체가 UTF-8이므로 확장 필드를 보지 않음. |
| 192 | 183 | let ignored = unicode_path("a.txt".as_bytes(), "b.txt"); |
| 193 | 184 | assert_eq!( |
| 194 | 삭제: names_agree(&single_entry_zip(b"a.txt", 0x0800, &ignored, b"hi\n")).unwrap(), | |
| 185 | 추가: listed_names(&single_entry_zip(b"a.txt", 0x0800, &ignored, b"hi\n")).unwrap(), | |
| 195 | 186 | ["a.txt"] |
| 196 | 187 | ); |
| 197 | 188 | } |
| 198 | 189 | |
| 199 | 190 | fn assert_rejected_without_output(bytes: &[u8], error: ErrorCode) { |
| 200 | 삭제: assert_eq!(names_agree(bytes), Err(error)); | |
| 191 | 추가: assert_eq!(listed_names(bytes), Err(error)); | |
| 201 | 192 | let s = Scratch::new(); |
| 202 | 193 | let events = extract(&s, bytes, None, Selection::All, None, Limits::default()); |
| 203 | 194 | let result = terminal(&events); |
| @@ -223,7 +214,10 @@ fn converted_names_colliding_with_other_paths_are_rejected_before_writes() { | ||
| 223 | 214 | let first = b"first.txt"; |
| 224 | 215 | let second = b"second.txt"; |
| 225 | 216 | let original = stored_entries_zip(&[(first, 0, &[], b"first"), (second, 0, &[], b"second")]); |
| 226 | 삭제: assert_eq!(names_agree(&original).unwrap(), ["first.txt", "second.txt"]); | |
| 217 | 추가: assert_eq!( | |
| 218 | 추가: listed_names(&original).unwrap(), | |
| 219 | 추가: ["first.txt", "second.txt"] | |
| 220 | 추가: ); | |
| 227 | 221 | for (first_name, second_name) in [ |
| 228 | 222 | ("회의록.txt", "회의록.txt"), |
| 229 | 223 | ("폴더/Memo.txt", "폴더/memo.txt"), |
| @@ -236,7 +230,7 @@ fn converted_names_colliding_with_other_paths_are_rejected_before_writes() { | ||
| 236 | 230 | (second.as_slice(), &second_extra, second_name), |
| 237 | 231 | ] { |
| 238 | 232 | let bytes = single_entry_zip(raw, 0, extra, b"hi\n"); |
| 239 | 삭제: assert_eq!(names_agree(&bytes).unwrap(), [name]); | |
| 233 | 추가: assert_eq!(listed_names(&bytes).unwrap(), [name]); | |
| 240 | 234 | } |
| 241 | 235 | let bytes = stored_entries_zip(&[ |
| 242 | 236 | (first, 0, &first_extra, b"first"), |
| @@ -251,26 +245,26 @@ fn legacy_and_hostile_names_stay_rejected() { | ||
| 251 | 245 | let cp949 = b"\xc8\xb8\xc0\xc7\xb7\xcf.txt"; |
| 252 | 246 | // 코드 페이지를 추측하지 않음. |
| 253 | 247 | assert_eq!( |
| 254 | 삭제: names_agree(&single_entry_zip(cp949, 0, &[], b"hi\n")), | |
| 248 | 추가: listed_names(&single_entry_zip(cp949, 0, &[], b"hi\n")), | |
| 255 | 249 | Err(ErrorCode::UnsupportedFeature) |
| 256 | 250 | ); |
| 257 | 251 | // UTF-8 플래그와 맞지 않는 이름은 손상으로 봄. |
| 258 | 252 | assert_eq!( |
| 259 | 삭제: names_agree(&single_entry_zip(cp949, 0x0800, &[], b"hi\n")), | |
| 253 | 추가: listed_names(&single_entry_zip(cp949, 0x0800, &[], b"hi\n")), | |
| 260 | 254 | Err(ErrorCode::Integrity) |
| 261 | 255 | ); |
| 262 | 256 | // 확장 필드로 들어온 이름도 같은 경로 검사를 거침. |
| 263 | 257 | for hostile in ["../escape.txt", "/absolute.txt", "C:drive.txt", "CON.txt"] { |
| 264 | 258 | let extra = unicode_path(b"safe.txt", hostile); |
| 265 | 259 | assert_eq!( |
| 266 | 삭제: names_agree(&single_entry_zip(b"safe.txt", 0, &extra, b"hi\n")), | |
| 260 | 추가: listed_names(&single_entry_zip(b"safe.txt", 0, &extra, b"hi\n")), | |
| 267 | 261 | Err(ErrorCode::UnsafePath), |
| 268 | 262 | "{hostile}" |
| 269 | 263 | ); |
| 270 | 264 | } |
| 271 | 265 | for hostile in ["../회의록.txt", "폴더/../../x"] { |
| 272 | 266 | assert_eq!( |
| 273 | 삭제: names_agree(&single_entry_zip(hostile.as_bytes(), 0, &[], b"hi\n")), | |
| 267 | 추가: listed_names(&single_entry_zip(hostile.as_bytes(), 0, &[], b"hi\n")), | |
| 274 | 268 | Err(ErrorCode::UnsafePath), |
| 275 | 269 | "{hostile}" |
| 276 | 270 | ); |
| @@ -280,20 +274,20 @@ fn legacy_and_hostile_names_stay_rejected() { | ||
| 280 | 274 | let len = broken.len(); |
| 281 | 275 | broken[len - 1] = 0xff; |
| 282 | 276 | assert_eq!( |
| 283 | 삭제: names_agree(&single_entry_zip(b"safe.txt", 0, &broken, b"hi\n")), | |
| 277 | 추가: listed_names(&single_entry_zip(b"safe.txt", 0, &broken, b"hi\n")), | |
| 284 | 278 | Err(ErrorCode::Integrity) |
| 285 | 279 | ); |
| 286 | 280 | let mut short = 0x7075u16.to_le_bytes().to_vec(); |
| 287 | 281 | short.extend([4, 0, 1, 0, 0, 0]); |
| 288 | 282 | assert_eq!( |
| 289 | 삭제: names_agree(&single_entry_zip(b"safe.txt", 0, &short, b"hi\n")), | |
| 283 | 추가: listed_names(&single_entry_zip(b"safe.txt", 0, &short, b"hi\n")), | |
| 290 | 284 | Err(ErrorCode::Integrity) |
| 291 | 285 | ); |
| 292 | 286 | // APPNOTE 4.6.9에 따라 모르는 버전의 확장 필드는 무시함. |
| 293 | 287 | let mut version = unicode_path(b"safe.txt", "x"); |
| 294 | 288 | version[4] = 2; |
| 295 | 289 | assert_eq!( |
| 296 | 삭제: names_agree(&single_entry_zip(b"safe.txt", 0, &version, b"hi\n")).unwrap(), | |
| 290 | 추가: listed_names(&single_entry_zip(b"safe.txt", 0, &version, b"hi\n")).unwrap(), | |
| 297 | 291 | ["safe.txt"] |
| 298 | 292 | ); |
| 299 | 293 | } |