| 1 | use std::{ |
| 2 | fs, |
| 3 | io::Write, |
| 4 | path::PathBuf, |
| 5 | process::{Command, Stdio}, |
| 6 | sync::atomic::{AtomicU64, Ordering}, |
| 7 | }; |
| 8 | use zipelo_archive_worker::{ |
| 9 | archive, |
| 10 | protocol::*, |
| 11 | wire::{Reader, Writer}, |
| 12 | }; |
| 13 | static NEXT: AtomicU64 = AtomicU64::new(0); |
| 14 | struct Scratch(PathBuf); |
| 15 | impl Scratch { |
| 16 | fn new() -> Self { |
| 17 | let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")) |
| 18 | .parent() |
| 19 | .unwrap() |
| 20 | .parent() |
| 21 | .unwrap() |
| 22 | .join("tests/rust-archive-worker/runs") |
| 23 | .join(format!( |
| 24 | "{}-{}", |
| 25 | std::process::id(), |
| 26 | NEXT.fetch_add(1, Ordering::Relaxed) |
| 27 | )); |
| 28 | fs::create_dir_all(path.parent().unwrap()).unwrap(); |
| 29 | let builder = fs::DirBuilder::new(); |
| 30 | #[cfg(unix)] |
| 31 | let mut builder = builder; |
| 32 | #[cfg(unix)] |
| 33 | { |
| 34 | use std::os::unix::fs::DirBuilderExt; |
| 35 | builder.mode(0o700); |
| 36 | } |
| 37 | builder.create(&path).unwrap(); |
| 38 | Self(path) |
| 39 | } |
| 40 | fn path(&self, name: &str) -> NativePath { |
| 41 | NativePath::from_path(&self.0.join(name)) |
| 42 | } |
| 43 | } |
| 44 | impl Drop for Scratch { |
| 45 | fn drop(&mut self) { |
| 46 | fs::remove_dir_all(&self.0).unwrap(); |
| 47 | } |
| 48 | } |
| 49 | fn execute(start: Start) -> Vec<Message> { |
| 50 | let mut data = Vec::new(); |
| 51 | Writer::new(&mut data, 17) |
| 52 | .send(&Message::Start(start)) |
| 53 | .unwrap(); |
| 54 | let mut command = Command::new(env!("CARGO_BIN_EXE_zipelo-archive-worker")); |
| 55 | command |
| 56 | .stdin(Stdio::piped()) |
| 57 | .stdout(Stdio::piped()) |
| 58 | .stderr(Stdio::piped()); |
| 59 | #[cfg(target_os = "linux")] |
| 60 | { |
| 61 | use std::os::unix::process::CommandExt; |
| 62 | #[repr(C)] |
| 63 | struct Limit { |
| 64 | soft: usize, |
| 65 | hard: usize, |
| 66 | } |
| 67 | unsafe extern "C" { |
| 68 | fn setrlimit(resource: i32, limit: *const Limit) -> i32; |
| 69 | } |
| 70 | // 자식 프로세스의 주소 공간만 512 MiB로 제한함. |
| 71 | unsafe { |
| 72 | command.pre_exec(|| { |
| 73 | let limit = Limit { |
| 74 | soft: 512 * 1024 * 1024, |
| 75 | hard: 512 * 1024 * 1024, |
| 76 | }; |
| 77 | if setrlimit(9, &limit) == 0 { |
| 78 | Ok(()) |
| 79 | } else { |
| 80 | Err(std::io::Error::last_os_error()) |
| 81 | } |
| 82 | }); |
| 83 | } |
| 84 | } |
| 85 | let mut child = command.spawn().unwrap(); |
| 86 | child.stdin.take().unwrap().write_all(&data).unwrap(); |
| 87 | let output = child.wait_with_output().unwrap(); |
| 88 | assert!(output.status.success(), "{:?}", output.stderr); |
| 89 | assert!(output.stderr.is_empty()); |
| 90 | let mut reader = Reader::new(output.stdout.as_slice()); |
| 91 | let mut events = Vec::new(); |
| 92 | while let Some((job, _, event)) = reader.read().unwrap() { |
| 93 | assert_eq!(job, 17); |
| 94 | events.push(event); |
| 95 | } |
| 96 | assert!(matches!(events.last(), Some(Message::Terminal(_)))); |
| 97 | events |
| 98 | } |
| 99 | fn terminal(events: &[Message]) -> &Terminal { |
| 100 | match events.last().unwrap() { |
| 101 | Message::Terminal(t) => t, |
| 102 | _ => panic!("missing terminal"), |
| 103 | } |
| 104 | } |
| 105 | fn extract( |
| 106 | s: &Scratch, |
| 107 | bytes: &[u8], |
| 108 | gzip: Option<&str>, |
| 109 | selection: Selection, |
| 110 | list_id: Option<ListId>, |
| 111 | limits: Limits, |
| 112 | ) -> Vec<Message> { |
| 113 | fs::write(s.0.join("input"), bytes).unwrap(); |
| 114 | if !s.0.join("output").exists() { |
| 115 | let d = fs::DirBuilder::new(); |
| 116 | #[cfg(unix)] |
| 117 | let mut d = d; |
| 118 | #[cfg(unix)] |
| 119 | { |
| 120 | use std::os::unix::fs::DirBuilderExt; |
| 121 | d.mode(0o700); |
| 122 | } |
| 123 | d.create(s.0.join("output")).unwrap(); |
| 124 | } |
| 125 | execute(Start { |
| 126 | action: Action::Extract { |
| 127 | archive: s.path("input"), |
| 128 | destination: s.path("output"), |
| 129 | selection, |
| 130 | list_id, |
| 131 | gzip_output_name: gzip.map(str::to_owned), |
| 132 | }, |
| 133 | limits, |
| 134 | }) |
| 135 | } |
| 136 | const PAYLOAD: &[u8] = b"Zipelo worker interoperability\n"; |
| 137 | fn basic(bytes: &[u8], gzip: Option<&str>, output: &str) { |
| 138 | let s = Scratch::new(); |
| 139 | let events = extract(&s, bytes, gzip, Selection::All, None, Limits::default()); |
| 140 | assert_eq!(terminal(&events).outcome, Outcome::Completed, "{events:?}"); |
| 141 | assert_eq!(terminal(&events).publication, Publication::Complete); |
| 142 | assert_eq!(fs::read(s.0.join("output").join(output)).unwrap(), PAYLOAD); |
| 143 | } |
| 144 | #[test] |
| 145 | fn stored_zip() { |
| 146 | basic( |
| 147 | include_bytes!("fixtures/store.zip"), |
| 148 | None, |
| 149 | "folder/hello.txt", |
| 150 | ); |
| 151 | } |
| 152 | #[test] |
| 153 | fn deflated_zip() { |
| 154 | basic( |
| 155 | include_bytes!("fixtures/deflate.zip"), |
| 156 | None, |
| 157 | "folder/hello.txt", |
| 158 | ); |
| 159 | } |
| 160 | #[test] |
| 161 | fn tar() { |
| 162 | basic( |
| 163 | include_bytes!("fixtures/sample.tar"), |
| 164 | None, |
| 165 | "folder/hello.txt", |
| 166 | ); |
| 167 | } |
| 168 | #[test] |
| 169 | fn tar_gzip() { |
| 170 | basic( |
| 171 | include_bytes!("fixtures/sample.tar.gz"), |
| 172 | None, |
| 173 | "folder/hello.txt", |
| 174 | ); |
| 175 | } |
| 176 | #[test] |
| 177 | fn gzip_explicit_name_ignores_fname() { |
| 178 | basic( |
| 179 | include_bytes!("fixtures/sample.gz"), |
| 180 | Some("chosen.txt"), |
| 181 | "chosen.txt", |
| 182 | ); |
| 183 | } |
| 184 | #[test] |
| 185 | fn gzip_concatenated_members() { |
| 186 | let s = Scratch::new(); |
| 187 | let events = extract( |
| 188 | &s, |
| 189 | include_bytes!("fixtures/concat.gz"), |
| 190 | Some("combined"), |
| 191 | Selection::All, |
| 192 | None, |
| 193 | Limits::default(), |
| 194 | ); |
| 195 | assert_eq!(terminal(&events).outcome, Outcome::Completed); |
| 196 | assert_eq!(fs::read(s.0.join("output/combined")).unwrap(), b"onetwo"); |
| 197 | } |
| 198 | #[test] |
| 199 | fn gzip_requires_leaf() { |
| 200 | for name in [None, Some("../escape"), Some("a/b")] { |
| 201 | let s = Scratch::new(); |
| 202 | let e = extract( |
| 203 | &s, |
| 204 | include_bytes!("fixtures/sample.gz"), |
| 205 | name, |
| 206 | Selection::All, |
| 207 | None, |
| 208 | Limits::default(), |
| 209 | ); |
| 210 | assert_eq!(terminal(&e).error, ErrorCode::InvalidRequest); |
| 211 | assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 0); |
| 212 | } |
| 213 | } |
| 214 | #[test] |
| 215 | fn archive_rejects_gzip_name() { |
| 216 | let s = Scratch::new(); |
| 217 | let e = extract( |
| 218 | &s, |
| 219 | include_bytes!("fixtures/store.zip"), |
| 220 | Some("a"), |
| 221 | Selection::All, |
| 222 | None, |
| 223 | Limits::default(), |
| 224 | ); |
| 225 | assert_eq!(terminal(&e).error, ErrorCode::InvalidRequest); |
| 226 | } |
| 227 | #[test] |
| 228 | fn no_clobber_and_preflight_no_partial_outputs() { |
| 229 | let s = Scratch::new(); |
| 230 | fs::create_dir(s.0.join("output")).unwrap(); |
| 231 | #[cfg(unix)] |
| 232 | { |
| 233 | use std::os::unix::fs::PermissionsExt; |
| 234 | fs::set_permissions(s.0.join("output"), fs::Permissions::from_mode(0o700)).unwrap(); |
| 235 | } |
| 236 | fs::create_dir(s.0.join("output/folder")).unwrap(); |
| 237 | #[cfg(unix)] |
| 238 | { |
| 239 | use std::os::unix::fs::PermissionsExt; |
| 240 | fs::set_permissions(s.0.join("output/folder"), fs::Permissions::from_mode(0o700)).unwrap(); |
| 241 | } |
| 242 | fs::write(s.0.join("output/folder/hello.txt"), b"preserve").unwrap(); |
| 243 | let e = extract( |
| 244 | &s, |
| 245 | include_bytes!("fixtures/store.zip"), |
| 246 | None, |
| 247 | Selection::All, |
| 248 | None, |
| 249 | Limits::default(), |
| 250 | ); |
| 251 | assert_eq!(terminal(&e).error, ErrorCode::Conflict); |
| 252 | assert_eq!( |
| 253 | fs::read(s.0.join("output/folder/hello.txt")).unwrap(), |
| 254 | b"preserve" |
| 255 | ); |
| 256 | assert!(!s.0.join("output/empty").exists()); |
| 257 | } |
| 258 | #[test] |
| 259 | fn unsafe_archives_reject_without_writes() { |
| 260 | for bytes in [ |
| 261 | include_bytes!("fixtures/traversal.zip").as_slice(), |
| 262 | include_bytes!("fixtures/absolute.zip"), |
| 263 | include_bytes!("fixtures/drive.zip"), |
| 264 | include_bytes!("fixtures/reserved.zip"), |
| 265 | include_bytes!("fixtures/link.zip"), |
| 266 | include_bytes!("fixtures/collision.zip"), |
| 267 | include_bytes!("fixtures/parent-collision.zip"), |
| 268 | ] { |
| 269 | let s = Scratch::new(); |
| 270 | let e = extract(&s, bytes, None, Selection::All, None, Limits::default()); |
| 271 | assert_eq!(terminal(&e).outcome, Outcome::Failed, "{e:?}"); |
| 272 | assert_eq!(terminal(&e).created_count, 0); |
| 273 | assert_eq!(terminal(&e).publication, Publication::None); |
| 274 | assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 0); |
| 275 | } |
| 276 | } |
| 277 | #[test] |
| 278 | fn bomb_rejects_before_writes() { |
| 279 | let s = Scratch::new(); |
| 280 | let e = extract( |
| 281 | &s, |
| 282 | include_bytes!("fixtures/bomb.zip"), |
| 283 | None, |
| 284 | Selection::All, |
| 285 | None, |
| 286 | Limits { |
| 287 | output: 1024, |
| 288 | ..Limits::default() |
| 289 | }, |
| 290 | ); |
| 291 | assert_eq!(terminal(&e).error, ErrorCode::Limit); |
| 292 | assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 0); |
| 293 | } |
| 294 | #[test] |
| 295 | fn corrupt_crc_and_truncation_reject_without_writes() { |
| 296 | let mut zip = include_bytes!("fixtures/store.zip").to_vec(); |
| 297 | let at = zip |
| 298 | .windows(PAYLOAD.len()) |
| 299 | .position(|b| b == PAYLOAD) |
| 300 | .unwrap(); |
| 301 | zip[at] ^= 1; |
| 302 | for bytes in [zip.as_slice(), &include_bytes!("fixtures/store.zip")[..40]] { |
| 303 | let s = Scratch::new(); |
| 304 | let e = extract(&s, bytes, None, Selection::All, None, Limits::default()); |
| 305 | assert_eq!(terminal(&e).outcome, Outcome::Failed); |
| 306 | assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 0); |
| 307 | } |
| 308 | } |
| 309 | fn listing(s: &Scratch) -> ListId { |
| 310 | let e = execute(Start { |
| 311 | action: Action::List { |
| 312 | archive: s.path("input"), |
| 313 | }, |
| 314 | limits: Limits::default(), |
| 315 | }); |
| 316 | assert_eq!(terminal(&e).outcome, Outcome::Completed); |
| 317 | e.into_iter() |
| 318 | .find_map(|m| { |
| 319 | if let Message::ListEnd { list_id, .. } = m { |
| 320 | Some(list_id) |
| 321 | } else { |
| 322 | None |
| 323 | } |
| 324 | }) |
| 325 | .unwrap() |
| 326 | } |
| 327 | #[test] |
| 328 | fn list_and_selected_extract() { |
| 329 | let s = Scratch::new(); |
| 330 | let bytes = include_bytes!("fixtures/store.zip"); |
| 331 | fs::write(s.0.join("input"), bytes).unwrap(); |
| 332 | let id = listing(&s); |
| 333 | let e = extract( |
| 334 | &s, |
| 335 | bytes, |
| 336 | None, |
| 337 | Selection::EntryIds(vec![0]), |
| 338 | Some(id), |
| 339 | Limits::default(), |
| 340 | ); |
| 341 | assert_eq!(terminal(&e).outcome, Outcome::Completed); |
| 342 | assert!(!s.0.join("output/empty").exists()); |
| 343 | assert_eq!( |
| 344 | fs::read(s.0.join("output/folder/hello.txt")).unwrap(), |
| 345 | PAYLOAD |
| 346 | ); |
| 347 | } |
| 348 | #[test] |
| 349 | fn stale_list_content_rejected() { |
| 350 | let s = Scratch::new(); |
| 351 | fs::write(s.0.join("input"), include_bytes!("fixtures/store.zip")).unwrap(); |
| 352 | let mut id = listing(&s); |
| 353 | id.archive_sha256[0] ^= 1; |
| 354 | let e = extract( |
| 355 | &s, |
| 356 | include_bytes!("fixtures/store.zip"), |
| 357 | None, |
| 358 | Selection::EntryIds(vec![0]), |
| 359 | Some(id), |
| 360 | Limits::default(), |
| 361 | ); |
| 362 | assert_eq!(terminal(&e).error, ErrorCode::SourceChanged); |
| 363 | assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 0); |
| 364 | } |
| 365 | #[test] |
| 366 | fn missing_duplicate_and_out_of_range_selection() { |
| 367 | for ids in [vec![], vec![0, 0], vec![999]] { |
| 368 | let s = Scratch::new(); |
| 369 | fs::write(s.0.join("input"), include_bytes!("fixtures/store.zip")).unwrap(); |
| 370 | let id = listing(&s); |
| 371 | let e = extract( |
| 372 | &s, |
| 373 | include_bytes!("fixtures/store.zip"), |
| 374 | None, |
| 375 | Selection::EntryIds(ids), |
| 376 | Some(id), |
| 377 | Limits::default(), |
| 378 | ); |
| 379 | assert_eq!(terminal(&e).error, ErrorCode::InvalidRequest); |
| 380 | } |
| 381 | let s = Scratch::new(); |
| 382 | let e = extract( |
| 383 | &s, |
| 384 | include_bytes!("fixtures/store.zip"), |
| 385 | None, |
| 386 | Selection::EntryIds(vec![0]), |
| 387 | None, |
| 388 | Limits::default(), |
| 389 | ); |
| 390 | assert_eq!(terminal(&e).error, ErrorCode::InvalidRequest); |
| 391 | } |
| 392 | #[test] |
| 393 | fn create_store_and_deflate_zip() { |
| 394 | for method in [Method::Store, Method::Deflate] { |
| 395 | let s = Scratch::new(); |
| 396 | fs::write(s.0.join("source"), PAYLOAD).unwrap(); |
| 397 | let e = execute(Start { |
| 398 | action: Action::CreateZip { |
| 399 | sources: vec![Source { |
| 400 | path: s.path("source"), |
| 401 | archive_name: "dir/hello.txt".into(), |
| 402 | }], |
| 403 | output_file: s.path("result.zip"), |
| 404 | method, |
| 405 | encryption: Encryption::None, |
| 406 | }, |
| 407 | limits: Limits::default(), |
| 408 | }); |
| 409 | assert_eq!(terminal(&e).outcome, Outcome::Completed, "{e:?}"); |
| 410 | let bytes = fs::read(s.0.join("result.zip")).unwrap(); |
| 411 | let parsed = archive::parse(&bytes, Limits::default(), true, &mut || Ok(())).unwrap(); |
| 412 | assert_eq!(parsed.members[0].data, PAYLOAD); |
| 413 | } |
| 414 | } |
| 415 | #[test] |
| 416 | fn encryption_password_eof_is_protocol_failure() { |
| 417 | let s = Scratch::new(); |
| 418 | let e = execute(Start { |
| 419 | action: Action::CreateZip { |
| 420 | sources: vec![], |
| 421 | output_file: s.path("result.zip"), |
| 422 | method: Method::Store, |
| 423 | encryption: Encryption::Aes256, |
| 424 | }, |
| 425 | limits: Limits::default(), |
| 426 | }); |
| 427 | assert_eq!(terminal(&e).error, ErrorCode::Protocol); |
| 428 | assert!(!s.0.join("result.zip").exists()); |
| 429 | } |
| 430 | #[test] |
| 431 | fn name_policy() { |
| 432 | for name in [ |
| 433 | "../a", "/a", "a\\b", "C:a", "a/../b", "a.", "a ", "COM1.txt", "a//b", "a/./b", |
| 434 | ] { |
| 435 | assert!(archive::valid_name(name, false).is_err(), "{name}"); |
| 436 | } |
| 437 | assert!(archive::valid_name("folder/한글.txt", false).is_ok()); |
| 438 | } |
| 439 | #[test] |
| 440 | fn frame_round_trip_and_secret_redaction() { |
| 441 | let mut b = Vec::new(); |
| 442 | Writer::new(&mut b, 42).send(&Message::Cancel).unwrap(); |
| 443 | let mut reader = Reader::new(b.as_slice()); |
| 444 | assert!(matches!( |
| 445 | reader.read().unwrap(), |
| 446 | Some((42, 0, Message::Cancel)) |
| 447 | )); |
| 448 | assert!(reader.read().unwrap().is_none()); |
| 449 | assert!( |
| 450 | !format!( |
| 451 | "{:?}", |
| 452 | Message::Password { |
| 453 | challenge_id: 1, |
| 454 | secret: Secret(b"private-password".to_vec()) |
| 455 | } |
| 456 | ) |
| 457 | .contains("private-password") |
| 458 | ); |
| 459 | } |
| 460 | #[test] |
| 461 | fn invalid_headers_are_rejected() { |
| 462 | let mut b = Vec::new(); |
| 463 | Writer::new(&mut b, 42).send(&Message::Cancel).unwrap(); |
| 464 | for (offset, value) in [(0, 0), (4, 2), (12, 1), (16, 0), (24, 1)] { |
| 465 | let mut bad = b.clone(); |
| 466 | bad[offset] = value; |
| 467 | assert!(Reader::new(bad.as_slice()).read().is_err()); |
| 468 | } |
| 469 | let mut big = b.clone(); |
| 470 | big[8..12].copy_from_slice(&1_048_577u32.to_le_bytes()); |
| 471 | assert!(Reader::new(big.as_slice()).read().is_err()); |
| 472 | assert!(Reader::new(&b[..16]).read().is_err()); |
| 473 | } |
| 474 | #[test] |
| 475 | fn terminal_is_final_frame() { |
| 476 | let t = Terminal { |
| 477 | outcome: Outcome::Failed, |
| 478 | error: ErrorCode::Io, |
| 479 | publication: Publication::Uncertain, |
| 480 | created_count: 0, |
| 481 | retained_partial_count: 0, |
| 482 | durability: Durability::Unconfirmed, |
| 483 | cleanup: Cleanup::Unconfirmed, |
| 484 | detail: "uncertain".into(), |
| 485 | }; |
| 486 | let mut b = Vec::new(); |
| 487 | let mut w = Writer::new(&mut b, 1); |
| 488 | w.send(&Message::Terminal(t)).unwrap(); |
| 489 | assert!(w.send(&Message::Cancel).is_err()); |
| 490 | } |
| 491 | #[cfg(unix)] |
| 492 | #[test] |
| 493 | fn symlink_parent_escape_is_rejected() { |
| 494 | use std::os::unix::fs::symlink; |
| 495 | let s = Scratch::new(); |
| 496 | let d = fs::DirBuilder::new(); |
| 497 | #[cfg(unix)] |
| 498 | let mut d = d; |
| 499 | use std::os::unix::fs::DirBuilderExt; |
| 500 | d.mode(0o700); |
| 501 | d.create(s.0.join("output")).unwrap(); |
| 502 | d.create(s.0.join("outside")).unwrap(); |
| 503 | symlink(s.0.join("outside"), s.0.join("output/folder")).unwrap(); |
| 504 | let e = extract( |
| 505 | &s, |
| 506 | include_bytes!("fixtures/store.zip"), |
| 507 | None, |
| 508 | Selection::All, |
| 509 | None, |
| 510 | Limits::default(), |
| 511 | ); |
| 512 | assert_eq!(terminal(&e).error, ErrorCode::UnsafePath); |
| 513 | assert_eq!(fs::read_dir(s.0.join("outside")).unwrap().count(), 0); |
| 514 | } |
| 515 | |
| 516 | #[test] |
| 517 | fn changed_source_is_reopen_error_before_decode() { |
| 518 | let s = Scratch::new(); |
| 519 | let bytes = include_bytes!("fixtures/store.zip"); |
| 520 | fs::write(s.0.join("input"), bytes).unwrap(); |
| 521 | let id = listing(&s); |
| 522 | let mut changed = bytes.to_vec(); |
| 523 | changed[40] ^= 1; |
| 524 | let e = extract( |
| 525 | &s, |
| 526 | &changed, |
| 527 | None, |
| 528 | Selection::EntryIds(vec![0]), |
| 529 | Some(id), |
| 530 | Limits::default(), |
| 531 | ); |
| 532 | assert_eq!(terminal(&e).error, ErrorCode::SourceChanged); |
| 533 | assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 0); |
| 534 | } |
| 535 | #[test] |
| 536 | fn cancel_ack_and_terminal_are_distinct() { |
| 537 | let s = Scratch::new(); |
| 538 | fs::write(s.0.join("source"), vec![0u8; 16 * 1024 * 1024]).unwrap(); |
| 539 | let start = Start { |
| 540 | action: Action::CreateZip { |
| 541 | sources: vec![Source { |
| 542 | path: s.path("source"), |
| 543 | archive_name: "data".into(), |
| 544 | }], |
| 545 | output_file: s.path("result.zip"), |
| 546 | method: Method::Deflate, |
| 547 | encryption: Encryption::None, |
| 548 | }, |
| 549 | limits: Limits::default(), |
| 550 | }; |
| 551 | let mut child = Command::new(env!("CARGO_BIN_EXE_zipelo-archive-worker")) |
| 552 | .stdin(Stdio::piped()) |
| 553 | .stdout(Stdio::piped()) |
| 554 | .stderr(Stdio::piped()) |
| 555 | .spawn() |
| 556 | .unwrap(); |
| 557 | let mut writer = Writer::new(child.stdin.take().unwrap(), 19); |
| 558 | let mut reader = Reader::new(child.stdout.take().unwrap()); |
| 559 | writer.send(&Message::Start(start)).unwrap(); |
| 560 | assert!(matches!( |
| 561 | reader.read().unwrap(), |
| 562 | Some((19, 0, Message::Accepted { .. })) |
| 563 | )); |
| 564 | writer.send(&Message::Cancel).unwrap(); |
| 565 | writer.send(&Message::Cancel).unwrap(); |
| 566 | let mut events = Vec::new(); |
| 567 | while let Some((_, _, m)) = reader.read().unwrap() { |
| 568 | events.push(m); |
| 569 | } |
| 570 | assert!(child.wait().unwrap().success()); |
| 571 | let terminal = terminal(&events); |
| 572 | assert!(matches!( |
| 573 | terminal.outcome, |
| 574 | Outcome::Cancelled | Outcome::Completed |
| 575 | )); |
| 576 | for m in &events { |
| 577 | if let Message::CancelAck { |
| 578 | request_sequence, |
| 579 | status, |
| 580 | } = m |
| 581 | { |
| 582 | assert!([1, 2].contains(request_sequence)); |
| 583 | assert!(matches!( |
| 584 | status, |
| 585 | CancelStatus::Requested |
| 586 | | CancelStatus::AlreadyRequested |
| 587 | | CancelStatus::TooLate |
| 588 | | CancelStatus::Finished |
| 589 | )); |
| 590 | } |
| 591 | } |
| 592 | assert!( |
| 593 | events |
| 594 | .iter() |
| 595 | .any(|m| matches!(m, Message::CancelAck { .. })), |
| 596 | "cancel must be consumed during bounded source read: {events:?}" |
| 597 | ); |
| 598 | } |
| 599 | |
| 600 | #[test] |
| 601 | fn encrypted_zip_password_eof_preserves_outputs() { |
| 602 | let mut bytes = include_bytes!("fixtures/store.zip").to_vec(); |
| 603 | bytes[6] |= 1; |
| 604 | let central = bytes.windows(4).position(|b| b == b"PK\x01\x02").unwrap(); |
| 605 | bytes[central + 8] |= 1; |
| 606 | let s = Scratch::new(); |
| 607 | let e = extract(&s, &bytes, None, Selection::All, None, Limits::default()); |
| 608 | assert_eq!(terminal(&e).error, ErrorCode::Protocol); |
| 609 | assert_eq!(terminal(&e).publication, Publication::None); |
| 610 | assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 0); |
| 611 | } |
| 612 | #[test] |
| 613 | fn uncertain_report_survives_codec() { |
| 614 | let t = Terminal { |
| 615 | outcome: Outcome::Failed, |
| 616 | error: ErrorCode::Io, |
| 617 | publication: Publication::Uncertain, |
| 618 | created_count: 2, |
| 619 | retained_partial_count: 1, |
| 620 | durability: Durability::Failed, |
| 621 | cleanup: Cleanup::Failed, |
| 622 | detail: "publication uncertain".into(), |
| 623 | }; |
| 624 | let mut bytes = Vec::new(); |
| 625 | Writer::new(&mut bytes, 88) |
| 626 | .send(&Message::Terminal(t.clone())) |
| 627 | .unwrap(); |
| 628 | let mut reader = Reader::new(bytes.as_slice()); |
| 629 | match reader.read().unwrap() { |
| 630 | Some((88, 0, Message::Terminal(actual))) => assert_eq!(actual, t), |
| 631 | other => panic!("{other:?}"), |
| 632 | }; |
| 633 | assert!(reader.read().unwrap().is_none()); |
| 634 | } |
| 635 | |
| 636 | fn path_fixture_zip(names: &[String]) -> Vec<u8> { |
| 637 | let mut output = Vec::new(); |
| 638 | let mut central = Vec::new(); |
| 639 | for name in names { |
| 640 | let offset = output.len() as u32; |
| 641 | output.extend(b"PK\x03\x04"); |
| 642 | for value in [20u16, 0x0800, 0, 0, 33] { |
| 643 | output.extend(value.to_le_bytes()); |
| 644 | } |
| 645 | for value in [0u32, 0, 0] { |
| 646 | output.extend(value.to_le_bytes()); |
| 647 | } |
| 648 | output.extend((name.len() as u16).to_le_bytes()); |
| 649 | output.extend(0u16.to_le_bytes()); |
| 650 | output.extend(name.as_bytes()); |
| 651 | central.extend(b"PK\x01\x02"); |
| 652 | for value in [0x0314u16, 20, 0x0800, 0, 0, 33] { |
| 653 | central.extend(value.to_le_bytes()); |
| 654 | } |
| 655 | for value in [0u32, 0, 0] { |
| 656 | central.extend(value.to_le_bytes()); |
| 657 | } |
| 658 | central.extend((name.len() as u16).to_le_bytes()); |
| 659 | for value in [0u16, 0, 0, 0] { |
| 660 | central.extend(value.to_le_bytes()); |
| 661 | } |
| 662 | central.extend((0o100600u32 << 16).to_le_bytes()); |
| 663 | central.extend(offset.to_le_bytes()); |
| 664 | central.extend(name.as_bytes()); |
| 665 | } |
| 666 | let offset = output.len() as u32; |
| 667 | output.extend(¢ral); |
| 668 | output.extend(b"PK\x05\x06"); |
| 669 | for value in [0u16, 0, names.len() as u16, names.len() as u16] { |
| 670 | output.extend(value.to_le_bytes()); |
| 671 | } |
| 672 | output.extend((central.len() as u32).to_le_bytes()); |
| 673 | output.extend(offset.to_le_bytes()); |
| 674 | output.extend(0u16.to_le_bytes()); |
| 675 | output |
| 676 | } |
| 677 | |
| 678 | fn assert_metadata_limit(names: &[String]) { |
| 679 | let scratch = Scratch::new(); |
| 680 | let events = extract( |
| 681 | &scratch, |
| 682 | &path_fixture_zip(names), |
| 683 | None, |
| 684 | Selection::All, |
| 685 | None, |
| 686 | Limits::default(), |
| 687 | ); |
| 688 | let result = terminal(&events); |
| 689 | assert_eq!(result.outcome, Outcome::Failed, "{events:?}"); |
| 690 | assert_eq!(result.error, ErrorCode::Limit, "{events:?}"); |
| 691 | assert_eq!(result.publication, Publication::None); |
| 692 | assert_eq!(result.created_count, 0); |
| 693 | assert_eq!(fs::read_dir(scratch.0.join("output")).unwrap().count(), 0); |
| 694 | } |
| 695 | |
| 696 | #[test] |
| 697 | fn deep_zip_returns_limit_without_abort_or_writes() { |
| 698 | let names = (0..100) |
| 699 | .map(|i| format!("{}file{i:03}", "a/".repeat(2000))) |
| 700 | .collect::<Vec<_>>(); |
| 701 | assert_metadata_limit(&names); |
| 702 | } |
| 703 | |
| 704 | #[test] |
| 705 | fn shallow_zip_parent_metadata_is_bounded() { |
| 706 | let names = (0..500) |
| 707 | .map(|i| { |
| 708 | format!( |
| 709 | "d{i:04}{}/{}file", |
| 710 | "a".repeat(180), |
| 711 | format!("{}/", "b".repeat(200)).repeat(7) |
| 712 | ) |
| 713 | }) |
| 714 | .collect::<Vec<_>>(); |
| 715 | assert!( |
| 716 | names |
| 717 | .iter() |
| 718 | .all(|n| n.split('/').count() <= archive::MAX_PATH_DEPTH) |
| 719 | ); |
| 720 | assert!( |
| 721 | archive::parse( |
| 722 | &path_fixture_zip(&names), |
| 723 | Limits::default(), |
| 724 | false, |
| 725 | &mut || Ok(()) |
| 726 | ) |
| 727 | .is_ok() |
| 728 | ); |
| 729 | assert_metadata_limit(&names); |
| 730 | } |
| 731 | |
| 732 | #[test] |
| 733 | fn aggregate_archive_name_metadata_is_bounded() { |
| 734 | let names = (0..1100) |
| 735 | .map(|i| { |
| 736 | format!( |
| 737 | "d{i:04}{}/{}file", |
| 738 | "a".repeat(180), |
| 739 | format!("{}/", "b".repeat(200)).repeat(9) |
| 740 | ) |
| 741 | }) |
| 742 | .collect::<Vec<_>>(); |
| 743 | let bytes = path_fixture_zip(&names); |
| 744 | assert!((bytes.len() as u64) < Limits::default().input); |
| 745 | assert!(matches!( |
| 746 | archive::parse(&bytes, Limits::default(), false, &mut || Ok(())), |
| 747 | Err(ErrorCode::Limit) |
| 748 | )); |
| 749 | assert_metadata_limit(&names); |
| 750 | } |
| 751 | |
| 752 | #[test] |
| 753 | fn path_depth_boundary_is_explicit() { |
| 754 | let accepted = format!("{}file", "a/".repeat(archive::MAX_PATH_DEPTH - 1)); |
| 755 | let rejected = format!("{}file", "a/".repeat(archive::MAX_PATH_DEPTH)); |
| 756 | assert!(archive::valid_name(&accepted, false).is_ok()); |
| 757 | assert_eq!(archive::valid_name(&rejected, false), Err(ErrorCode::Limit)); |
| 758 | } |
| 759 | |
| 760 | fn zeros_gzip(length: usize) -> Vec<u8> { |
| 761 | let mut gzip = vec![31, 139, 8, 0, 0, 0, 0, 0, 0, 255]; |
| 762 | let mut left = length; |
| 763 | loop { |
| 764 | let size = left.min(u16::MAX as usize) as u16; |
| 765 | left -= size as usize; |
| 766 | gzip.push(u8::from(left == 0)); |
| 767 | gzip.extend(size.to_le_bytes()); |
| 768 | gzip.extend((!size).to_le_bytes()); |
| 769 | gzip.resize(gzip.len() + size as usize, 0); |
| 770 | if left == 0 { |
| 771 | break; |
| 772 | } |
| 773 | } |
| 774 | gzip.extend(zlib_rs::crc32::crc32(0, &vec![0; length]).to_le_bytes()); |
| 775 | gzip.extend((length as u32).to_le_bytes()); |
| 776 | gzip |
| 777 | } |
| 778 | |
| 779 | #[test] |
| 780 | fn zero_payload_gzip_is_not_tar() { |
| 781 | for length in [512, 1024, 1536] { |
| 782 | let scratch = Scratch::new(); |
| 783 | let bytes = zeros_gzip(length); |
| 784 | let parsed = archive::parse(&bytes, Limits::default(), true, &mut || Ok(())).unwrap(); |
| 785 | assert_eq!(parsed.format, Format::Gzip); |
| 786 | let events = extract( |
| 787 | &scratch, |
| 788 | &bytes, |
| 789 | Some("zeros.bin"), |
| 790 | Selection::All, |
| 791 | None, |
| 792 | Limits::default(), |
| 793 | ); |
| 794 | assert_eq!(terminal(&events).outcome, Outcome::Completed, "{events:?}"); |
| 795 | assert_eq!( |
| 796 | fs::read(scratch.0.join("output/zeros.bin")).unwrap(), |
| 797 | vec![0; length] |
| 798 | ); |
| 799 | fs::write(scratch.0.join("input"), &bytes).unwrap(); |
| 800 | let list_id = listing(&scratch); |
| 801 | assert_eq!(list_id.format, Format::Gzip); |
| 802 | } |
| 803 | } |
| 804 | |
| 805 | const ENCRYPTED_PAYLOAD: &[u8] = b"Zipelo encrypted interoperability\nZipelo encrypted interoperability\nZipelo encrypted interoperability\nZipelo encrypted interoperability\nZipelo encrypted interoperability\nZipelo encrypted interoperability\nZipelo encrypted interoperability\nZipelo encrypted interoperability\n"; |
| 806 | const TEST_PASSWORD: &[u8] = b"fixture-password"; |
| 807 | const AES_ZIP: &[u8] = include_bytes!("fixtures/aes2-deflate.zip"); |
| 808 | fn interactive( |
| 809 | start: Start, |
| 810 | mut respond: impl FnMut(u64, u32, PasswordPurpose) -> Vec<Message>, |
| 811 | ) -> Vec<Message> { |
| 812 | use std::{io::Read, sync::mpsc, time::Duration}; |
| 813 | let mut child = Command::new(env!("CARGO_BIN_EXE_zipelo-archive-worker")) |
| 814 | .stdin(Stdio::piped()) |
| 815 | .stdout(Stdio::piped()) |
| 816 | .stderr(Stdio::piped()) |
| 817 | .spawn() |
| 818 | .unwrap(); |
| 819 | let mut writer = Some(Writer::new(child.stdin.take().unwrap(), 17)); |
| 820 | writer |
| 821 | .as_mut() |
| 822 | .unwrap() |
| 823 | .send(&Message::Start(start)) |
| 824 | .unwrap(); |
| 825 | let output = child.stdout.take().unwrap(); |
| 826 | let mut errors = child.stderr.take().unwrap(); |
| 827 | let error_thread = std::thread::spawn(move || { |
| 828 | let mut bytes = Vec::new(); |
| 829 | errors.read_to_end(&mut bytes).unwrap(); |
| 830 | bytes |
| 831 | }); |
| 832 | let (sender, receiver) = mpsc::channel(); |
| 833 | let reader_thread = std::thread::spawn(move || { |
| 834 | let mut reader = Reader::new(output); |
| 835 | loop { |
| 836 | let event = reader.read().map(|v| { |
| 837 | v.map(|(job, _, message)| { |
| 838 | assert_eq!(job, 17); |
| 839 | message |
| 840 | }) |
| 841 | }); |
| 842 | let done = !matches!(event, Ok(Some(_))); |
| 843 | if sender.send(event).is_err() || done { |
| 844 | break; |
| 845 | } |
| 846 | } |
| 847 | }); |
| 848 | let mut events = Vec::new(); |
| 849 | loop { |
| 850 | let event = match receiver.recv_timeout(Duration::from_secs(10)) { |
| 851 | Ok(event) => event.unwrap(), |
| 852 | Err(error) => { |
| 853 | child.kill().unwrap(); |
| 854 | child.wait().unwrap(); |
| 855 | panic!("worker timeout: {error}"); |
| 856 | } |
| 857 | }; |
| 858 | let Some(event) = event else { |
| 859 | break; |
| 860 | }; |
| 861 | if let Message::PasswordRequired { |
| 862 | challenge_id, |
| 863 | attempt, |
| 864 | purpose, |
| 865 | } = &event |
| 866 | { |
| 867 | let commands = respond(*challenge_id, *attempt, *purpose); |
| 868 | if commands.is_empty() { |
| 869 | writer = None; |
| 870 | } else { |
| 871 | for command in commands { |
| 872 | writer.as_mut().unwrap().send(&command).unwrap(); |
| 873 | } |
| 874 | } |
| 875 | } |
| 876 | if matches!(event, Message::Terminal(_)) { |
| 877 | writer = None; |
| 878 | } |
| 879 | events.push(event); |
| 880 | } |
| 881 | assert!(child.wait().unwrap().success()); |
| 882 | reader_thread.join().unwrap(); |
| 883 | assert!(error_thread.join().unwrap().is_empty()); |
| 884 | assert!(matches!(events.last(), Some(Message::Terminal(_)))); |
| 885 | events |
| 886 | } |
| 887 | fn password_reply(id: u64, password: &[u8]) -> Vec<Message> { |
| 888 | vec![Message::Password { |
| 889 | challenge_id: id, |
| 890 | secret: Secret(password.to_vec()), |
| 891 | }] |
| 892 | } |
| 893 | fn encrypted_start(s: &Scratch, bytes: &[u8]) -> Start { |
| 894 | fs::write(s.0.join("input"), bytes).unwrap(); |
| 895 | fs::create_dir(s.0.join("output")).unwrap(); |
| 896 | #[cfg(unix)] |
| 897 | { |
| 898 | use std::os::unix::fs::PermissionsExt; |
| 899 | fs::set_permissions(s.0.join("output"), fs::Permissions::from_mode(0o700)).unwrap(); |
| 900 | } |
| 901 | Start { |
| 902 | action: Action::Extract { |
| 903 | archive: s.path("input"), |
| 904 | destination: s.path("output"), |
| 905 | selection: Selection::All, |
| 906 | list_id: None, |
| 907 | gzip_output_name: None, |
| 908 | }, |
| 909 | limits: Limits::default(), |
| 910 | } |
| 911 | } |
| 912 | fn no_encrypted_output(s: &Scratch, events: &[Message], error: ErrorCode) { |
| 913 | assert_eq!(terminal(events).error, error, "{events:?}"); |
| 914 | assert_eq!(terminal(events).publication, Publication::None); |
| 915 | assert_eq!(terminal(events).created_count, 0); |
| 916 | assert!(!events.iter().any(|e| matches!(e, Message::Output { .. }))); |
| 917 | assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 0); |
| 918 | } |
| 919 | #[test] |
| 920 | fn independent_encrypted_fixtures_list_and_extract() { |
| 921 | for bytes in [ |
| 922 | include_bytes!("fixtures/aes1-store.zip").as_slice(), |
| 923 | include_bytes!("fixtures/aes1-deflate.zip").as_slice(), |
| 924 | include_bytes!("fixtures/aes2-store.zip").as_slice(), |
| 925 | AES_ZIP, |
| 926 | include_bytes!("fixtures/zipcrypto-store.zip").as_slice(), |
| 927 | include_bytes!("fixtures/zipcrypto-deflate.zip").as_slice(), |
| 928 | ] { |
| 929 | let s = Scratch::new(); |
| 930 | let start = encrypted_start(&s, bytes); |
| 931 | let listing = execute(Start { |
| 932 | action: Action::List { |
| 933 | archive: s.path("input"), |
| 934 | }, |
| 935 | limits: Limits::default(), |
| 936 | }); |
| 937 | assert_eq!( |
| 938 | terminal(&listing).outcome, |
| 939 | Outcome::Completed, |
| 940 | "{listing:?}" |
| 941 | ); |
| 942 | assert!(listing.iter().any(|e| matches!( |
| 943 | e, |
| 944 | Message::Entry(Entry { |
| 945 | encrypted: true, |
| 946 | .. |
| 947 | }) |
| 948 | ))); |
| 949 | assert!( |
| 950 | !listing |
| 951 | .iter() |
| 952 | .any(|e| matches!(e, Message::PasswordRequired { .. })) |
| 953 | ); |
| 954 | let events = interactive(start, |id, attempt, purpose| { |
| 955 | assert_eq!(purpose, PasswordPurpose::Decrypt); |
| 956 | assert_eq!(attempt, 1); |
| 957 | password_reply(id, TEST_PASSWORD) |
| 958 | }); |
| 959 | assert_eq!(terminal(&events).outcome, Outcome::Completed, "{events:?}"); |
| 960 | assert_eq!( |
| 961 | fs::read(s.0.join("output/payload.bin")).unwrap(), |
| 962 | ENCRYPTED_PAYLOAD |
| 963 | ); |
| 964 | } |
| 965 | } |
| 966 | #[test] |
| 967 | fn aes_creation_uses_password_flow_and_independent_verification() { |
| 968 | for method in [Method::Store, Method::Deflate] { |
| 969 | let s = Scratch::new(); |
| 970 | fs::write(s.0.join("source"), ENCRYPTED_PAYLOAD).unwrap(); |
| 971 | let events = interactive( |
| 972 | Start { |
| 973 | action: Action::CreateZip { |
| 974 | sources: vec![Source { |
| 975 | path: s.path("source"), |
| 976 | archive_name: "payload.bin".into(), |
| 977 | }], |
| 978 | output_file: s.path("encrypted.zip"), |
| 979 | method, |
| 980 | encryption: Encryption::Aes256, |
| 981 | }, |
| 982 | limits: Limits::default(), |
| 983 | }, |
| 984 | |id, attempt, purpose| { |
| 985 | assert_eq!(purpose, PasswordPurpose::Encrypt); |
| 986 | assert_eq!(attempt, 1); |
| 987 | password_reply(id, TEST_PASSWORD) |
| 988 | }, |
| 989 | ); |
| 990 | assert_eq!(terminal(&events).outcome, Outcome::Completed, "{events:?}"); |
| 991 | assert!(events.iter().any(|e| matches!( |
| 992 | e, |
| 993 | Message::Accepted { |
| 994 | encryption: true, |
| 995 | .. |
| 996 | } |
| 997 | ))); |
| 998 | #[cfg(target_os = "linux")] |
| 999 | { |
| 1000 | let helper = PathBuf::from(env!("CARGO_MANIFEST_DIR")) |
| 1001 | .join("../../tests/rust-archive-worker/encryption_fixtures.py"); |
| 1002 | assert!( |
| 1003 | Command::new("python3") |
| 1004 | .arg(helper) |
| 1005 | .arg("--verify") |
| 1006 | .arg(s.0.join("encrypted.zip")) |
| 1007 | .status() |
| 1008 | .unwrap() |
| 1009 | .success() |
| 1010 | ); |
| 1011 | } |
| 1012 | let bytes = fs::read(s.0.join("encrypted.zip")).unwrap(); |
| 1013 | let start = encrypted_start(&s, &bytes); |
| 1014 | let events = interactive(start, |id, _, _| password_reply(id, TEST_PASSWORD)); |
| 1015 | assert_eq!(terminal(&events).outcome, Outcome::Completed, "{events:?}"); |
| 1016 | assert_eq!( |
| 1017 | fs::read(s.0.join("output/payload.bin")).unwrap(), |
| 1018 | ENCRYPTED_PAYLOAD |
| 1019 | ); |
| 1020 | } |
| 1021 | } |
| 1022 | #[test] |
| 1023 | fn wrong_password_retries_with_new_challenge_then_succeeds() { |
| 1024 | let s = Scratch::new(); |
| 1025 | let start = encrypted_start(&s, AES_ZIP); |
| 1026 | let mut previous = 0; |
| 1027 | let events = interactive(start, |id, attempt, _| { |
| 1028 | assert!(id > previous); |
| 1029 | previous = id; |
| 1030 | password_reply( |
| 1031 | id, |
| 1032 | if attempt == 1 { |
| 1033 | b"wrong" |
| 1034 | } else { |
| 1035 | TEST_PASSWORD |
| 1036 | }, |
| 1037 | ) |
| 1038 | }); |
| 1039 | assert_eq!(terminal(&events).outcome, Outcome::Completed); |
| 1040 | assert_eq!(previous, 2); |
| 1041 | } |
| 1042 | #[test] |
| 1043 | fn wrong_password_attempts_are_bounded_without_writes() { |
| 1044 | let s = Scratch::new(); |
| 1045 | let start = encrypted_start(&s, AES_ZIP); |
| 1046 | let mut attempts = 0; |
| 1047 | let events = interactive(start, |id, attempt, _| { |
| 1048 | attempts = attempt; |
| 1049 | password_reply(id, b"wrong") |
| 1050 | }); |
| 1051 | assert_eq!(attempts, 3); |
| 1052 | no_encrypted_output(&s, &events, ErrorCode::WrongPassword); |
| 1053 | } |
| 1054 | #[test] |
| 1055 | fn cancellation_while_waiting_for_password_is_acknowledged() { |
| 1056 | let s = Scratch::new(); |
| 1057 | let start = encrypted_start(&s, AES_ZIP); |
| 1058 | let events = interactive(start, |_, _, _| vec![Message::Cancel]); |
| 1059 | assert_eq!(terminal(&events).outcome, Outcome::Cancelled); |
| 1060 | assert!(events.iter().any(|e| matches!( |
| 1061 | e, |
| 1062 | Message::CancelAck { |
| 1063 | status: CancelStatus::Requested, |
| 1064 | .. |
| 1065 | } |
| 1066 | ))); |
| 1067 | no_encrypted_output(&s, &events, ErrorCode::None); |
| 1068 | } |
| 1069 | #[test] |
| 1070 | fn stale_and_mismatched_password_challenges_fail_without_writes() { |
| 1071 | for stale in [false, true] { |
| 1072 | let s = Scratch::new(); |
| 1073 | let start = encrypted_start(&s, AES_ZIP); |
| 1074 | let events = interactive(start, |id, attempt, _| { |
| 1075 | if stale && attempt == 1 { |
| 1076 | password_reply(id, b"wrong") |
| 1077 | } else { |
| 1078 | password_reply(if stale { id - 1 } else { id + 1 }, TEST_PASSWORD) |
| 1079 | } |
| 1080 | }); |
| 1081 | no_encrypted_output(&s, &events, ErrorCode::Protocol); |
| 1082 | } |
| 1083 | } |
| 1084 | #[test] |
| 1085 | fn password_input_eof_fails_without_writes() { |
| 1086 | let s = Scratch::new(); |
| 1087 | let start = encrypted_start(&s, AES_ZIP); |
| 1088 | let events = interactive(start, |_, _, _| vec![]); |
| 1089 | no_encrypted_output(&s, &events, ErrorCode::Protocol); |
| 1090 | } |
| 1091 | #[test] |
| 1092 | fn aes_authentication_failure_never_publishes_plaintext() { |
| 1093 | for tamper_tag in [false, true] { |
| 1094 | let mut bytes = AES_ZIP.to_vec(); |
| 1095 | let central = bytes.windows(4).position(|b| b == b"PK\x01\x02").unwrap(); |
| 1096 | if tamper_tag { |
| 1097 | bytes[central - 1] ^= 1; |
| 1098 | } else { |
| 1099 | bytes[30 + b"payload.bin".len() + 11 + 18] ^= 1; |
| 1100 | } |
| 1101 | let s = Scratch::new(); |
| 1102 | let start = encrypted_start(&s, &bytes); |
| 1103 | let events = interactive(start, |id, _, _| password_reply(id, TEST_PASSWORD)); |
| 1104 | no_encrypted_output(&s, &events, ErrorCode::Integrity); |
| 1105 | } |
| 1106 | } |
| 1107 | #[test] |
| 1108 | fn aes1_crc_and_extra_consistency_are_checked() { |
| 1109 | let original = include_bytes!("fixtures/aes1-store.zip"); |
| 1110 | for corrupt_extra in [false, true] { |
| 1111 | let mut bytes = original.to_vec(); |
| 1112 | let central = bytes.windows(4).position(|b| b == b"PK\x01\x02").unwrap(); |
| 1113 | if corrupt_extra { |
| 1114 | bytes[30 + b"payload.bin".len() + 4] = 2; |
| 1115 | } else { |
| 1116 | bytes[14] ^= 1; |
| 1117 | bytes[central + 16] ^= 1; |
| 1118 | } |
| 1119 | let s = Scratch::new(); |
| 1120 | let start = encrypted_start(&s, &bytes); |
| 1121 | let events = interactive(start, |id, _, _| password_reply(id, TEST_PASSWORD)); |
| 1122 | no_encrypted_output(&s, &events, ErrorCode::Integrity); |
| 1123 | } |
| 1124 | } |
| 1125 | #[test] |
| 1126 | fn empty_aes_members_and_random_salts_round_trip() { |
| 1127 | let members = vec![archive::Member { |
| 1128 | entry: Entry { |
| 1129 | entry_id: 0, |
| 1130 | name: "empty".into(), |
| 1131 | kind: EntryKind::File, |
| 1132 | size: 0, |
| 1133 | compressed_size: 0, |
| 1134 | encrypted: false, |
| 1135 | }, |
| 1136 | data: vec![], |
| 1137 | }]; |
| 1138 | let a = archive::create_zip_with_password( |
| 1139 | &members, |
| 1140 | Method::Store, |
| 1141 | Limits::default(), |
| 1142 | Some(TEST_PASSWORD), |
| 1143 | &mut || Ok(()), |
| 1144 | ) |
| 1145 | .unwrap(); |
| 1146 | let b = archive::create_zip_with_password( |
| 1147 | &members, |
| 1148 | Method::Store, |
| 1149 | Limits::default(), |
| 1150 | Some(TEST_PASSWORD), |
| 1151 | &mut || Ok(()), |
| 1152 | ) |
| 1153 | .unwrap(); |
| 1154 | assert_ne!(a, b); |
| 1155 | let decoded = archive::parse_with_password( |
| 1156 | &a, |
| 1157 | Limits::default(), |
| 1158 | true, |
| 1159 | Some(TEST_PASSWORD), |
| 1160 | &mut || Ok(()), |
| 1161 | ) |
| 1162 | .unwrap(); |
| 1163 | assert!(decoded.members[0].data.is_empty()); |
| 1164 | } |
| 1165 | |
| 1166 | #[test] |
| 1167 | fn password_racing_after_cancel_does_not_override_cancellation() { |
| 1168 | let s = Scratch::new(); |
| 1169 | let start = encrypted_start(&s, AES_ZIP); |
| 1170 | let events = interactive(start, |id, _, _| { |
| 1171 | vec![ |
| 1172 | Message::Cancel, |
| 1173 | Message::Password { |
| 1174 | challenge_id: id, |
| 1175 | secret: Secret(TEST_PASSWORD.to_vec()), |
| 1176 | }, |
| 1177 | ] |
| 1178 | }); |
| 1179 | assert_eq!(terminal(&events).outcome, Outcome::Cancelled); |
| 1180 | no_encrypted_output(&s, &events, ErrorCode::None); |
| 1181 | } |
| 1182 | #[test] |
| 1183 | fn empty_encryption_password_never_creates_zip() { |
| 1184 | let s = Scratch::new(); |
| 1185 | let events = interactive( |
| 1186 | Start { |
| 1187 | action: Action::CreateZip { |
| 1188 | sources: vec![], |
| 1189 | output_file: s.path("empty.zip"), |
| 1190 | method: Method::Store, |
| 1191 | encryption: Encryption::Aes256, |
| 1192 | }, |
| 1193 | limits: Limits::default(), |
| 1194 | }, |
| 1195 | |id, _, _| password_reply(id, b""), |
| 1196 | ); |
| 1197 | assert_eq!(terminal(&events).error, ErrorCode::InvalidRequest); |
| 1198 | assert_eq!(terminal(&events).publication, Publication::None); |
| 1199 | assert!(!s.0.join("empty.zip").exists()); |
| 1200 | } |
| 1201 | |
| 1202 | const SEVEN_PAYLOAD: &[u8] = b"Zipelo 7z interoperability\n"; |
| 1203 | fn seven_fixture(name: &str) -> Vec<u8> { |
| 1204 | fs::read( |
| 1205 | PathBuf::from(env!("CARGO_MANIFEST_DIR")) |
| 1206 | .join("../../tests/rust-archive-worker/fixtures/7z") |
| 1207 | .join(name), |
| 1208 | ) |
| 1209 | .unwrap() |
| 1210 | } |
| 1211 | #[test] |
| 1212 | fn seven_zip_lzma_lzma2_and_copy_interoperate() { |
| 1213 | for name in [ |
| 1214 | "copy.7z", |
| 1215 | "lzma.7z", |
| 1216 | "lzma2.7z", |
| 1217 | "properties-0.7z", |
| 1218 | "properties-1.7z", |
| 1219 | "properties-2.7z", |
| 1220 | "properties-3.7z", |
| 1221 | "libarchive-lzma1.7z", |
| 1222 | "libarchive-lzma2.7z", |
| 1223 | ] { |
| 1224 | let bytes = seven_fixture(name); |
| 1225 | let catalog = archive::parse(&bytes, Limits::default(), true, &mut || Ok(())) |
| 1226 | .unwrap_or_else(|e| panic!("{name}: {e:?}")); |
| 1227 | assert_eq!(catalog.format, Format::SevenZip); |
| 1228 | assert_eq!(catalog.members[0].data, SEVEN_PAYLOAD.repeat(100), "{name}"); |
| 1229 | let s = Scratch::new(); |
| 1230 | let events = extract(&s, &bytes, None, Selection::All, None, Limits::default()); |
| 1231 | assert_eq!( |
| 1232 | terminal(&events).outcome, |
| 1233 | Outcome::Completed, |
| 1234 | "{name}: {events:?}" |
| 1235 | ); |
| 1236 | assert_eq!( |
| 1237 | fs::read(s.0.join("output/folder/hello.txt")).unwrap(), |
| 1238 | SEVEN_PAYLOAD.repeat(100) |
| 1239 | ); |
| 1240 | } |
| 1241 | } |
| 1242 | #[test] |
| 1243 | fn seven_zip_encoded_header_solid_and_empty_entries() { |
| 1244 | let s = Scratch::new(); |
| 1245 | let bytes = seven_fixture("encoded-solid.7z"); |
| 1246 | let catalog = archive::parse(&bytes, Limits::default(), false, &mut || Ok(())).unwrap(); |
| 1247 | assert_eq!(catalog.members.len(), 4); |
| 1248 | let events = extract(&s, &bytes, None, Selection::All, None, Limits::default()); |
| 1249 | assert_eq!(terminal(&events).outcome, Outcome::Completed, "{events:?}"); |
| 1250 | assert_eq!(fs::read(s.0.join("output/folder/empty")).unwrap(), b""); |
| 1251 | assert_eq!( |
| 1252 | fs::read(s.0.join("output/folder/hello.txt")).unwrap(), |
| 1253 | SEVEN_PAYLOAD.repeat(100) |
| 1254 | ); |
| 1255 | let mut reverse = SEVEN_PAYLOAD.repeat(100); |
| 1256 | reverse.reverse(); |
| 1257 | assert_eq!(fs::read(s.0.join("output/한글.txt")).unwrap(), reverse); |
| 1258 | } |
| 1259 | #[test] |
| 1260 | fn seven_zip_long_matches_and_lzma2_chunks() { |
| 1261 | for name in ["long-match.7z", "lzma2-chunks.7z"] { |
| 1262 | let bytes = seven_fixture(name); |
| 1263 | let catalog = archive::parse(&bytes, Limits::default(), true, &mut || Ok(())) |
| 1264 | .unwrap_or_else(|e| panic!("{name}: {e:?}")); |
| 1265 | if name == "long-match.7z" { |
| 1266 | assert_eq!(catalog.members[0].data, SEVEN_PAYLOAD.repeat(10000)); |
| 1267 | } else { |
| 1268 | let expected = (0..100000u64) |
| 1269 | .map(|i| (((i * 1103515245 + (i >> 2) * 12345) >> ((i % 4) * 8)) & 255) as u8) |
| 1270 | .collect::<Vec<_>>(); |
| 1271 | assert_eq!(catalog.members[0].data, expected); |
| 1272 | } |
| 1273 | } |
| 1274 | } |
| 1275 | #[test] |
| 1276 | fn seven_zip_malicious_inputs_never_write() { |
| 1277 | for name in [ |
| 1278 | "unsafe-dotdot.7z", |
| 1279 | "unsafe-absolute.7z", |
| 1280 | "unsafe-drive.7z", |
| 1281 | "unsafe-backslash.7z", |
| 1282 | "unsafe-deep.7z", |
| 1283 | "symlink.7z", |
| 1284 | "collision.7z", |
| 1285 | "bad-payload.7z", |
| 1286 | "bad-crc.7z", |
| 1287 | "bad-dictionary.7z", |
| 1288 | ] { |
| 1289 | let s = Scratch::new(); |
| 1290 | let bytes = seven_fixture(name); |
| 1291 | let events = extract(&s, &bytes, None, Selection::All, None, Limits::default()); |
| 1292 | assert_eq!( |
| 1293 | terminal(&events).outcome, |
| 1294 | Outcome::Failed, |
| 1295 | "{name}: {events:?}" |
| 1296 | ); |
| 1297 | assert_eq!(terminal(&events).publication, Publication::None); |
| 1298 | assert_eq!(terminal(&events).created_count, 0); |
| 1299 | assert!(!events.iter().any(|e| matches!(e, Message::Output { .. }))); |
| 1300 | assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 0); |
| 1301 | assert!(!s.0.join("outside.txt").exists()); |
| 1302 | } |
| 1303 | } |
| 1304 | |
| 1305 | #[test] |
| 1306 | fn seven_zip_format_wire_tag_preserves_existing_encodings() { |
| 1307 | for (tag, format) in [ |
| 1308 | Format::Zip, |
| 1309 | Format::Tar, |
| 1310 | Format::Gzip, |
| 1311 | Format::TarGzip, |
| 1312 | Format::SevenZip, |
| 1313 | ] |
| 1314 | .into_iter() |
| 1315 | .enumerate() |
| 1316 | { |
| 1317 | let token = ListId { |
| 1318 | catalog_version: 1, |
| 1319 | format, |
| 1320 | source_object: SourceObject::Unix { |
| 1321 | device: 1, |
| 1322 | inode: 2, |
| 1323 | }, |
| 1324 | archive_bytes: 3, |
| 1325 | archive_sha256: [4; 32], |
| 1326 | }; |
| 1327 | let mut bytes = Vec::new(); |
| 1328 | Writer::new(&mut bytes, 17) |
| 1329 | .send(&Message::ListEnd { |
| 1330 | entry_count: 5, |
| 1331 | list_id: token.clone(), |
| 1332 | }) |
| 1333 | .unwrap(); |
| 1334 | assert_eq!(bytes[38], tag as u8); |
| 1335 | match Reader::new(bytes.as_slice()).read().unwrap().unwrap().2 { |
| 1336 | Message::ListEnd { |
| 1337 | entry_count, |
| 1338 | list_id, |
| 1339 | } => { |
| 1340 | assert_eq!(entry_count, 5); |
| 1341 | assert_eq!(list_id, token); |
| 1342 | } |
| 1343 | _ => panic!("expected ListEnd"), |
| 1344 | } |
| 1345 | } |
| 1346 | } |
| 1347 | #[test] |
| 1348 | fn seven_zip_listing_token_and_selection() { |
| 1349 | let s = Scratch::new(); |
| 1350 | let bytes = seven_fixture("encoded-solid.7z"); |
| 1351 | fs::write(s.0.join("input"), &bytes).unwrap(); |
| 1352 | let events = execute(Start { |
| 1353 | action: Action::List { |
| 1354 | archive: s.path("input"), |
| 1355 | }, |
| 1356 | limits: Limits::default(), |
| 1357 | }); |
| 1358 | assert_eq!(terminal(&events).outcome, Outcome::Completed); |
| 1359 | let list_id = events |
| 1360 | .into_iter() |
| 1361 | .find_map(|e| { |
| 1362 | if let Message::ListEnd { list_id, .. } = e { |
| 1363 | Some(list_id) |
| 1364 | } else { |
| 1365 | None |
| 1366 | } |
| 1367 | }) |
| 1368 | .unwrap(); |
| 1369 | assert_eq!(list_id.format, Format::SevenZip); |
| 1370 | let events = extract( |
| 1371 | &s, |
| 1372 | &bytes, |
| 1373 | None, |
| 1374 | Selection::EntryIds(vec![3]), |
| 1375 | Some(list_id), |
| 1376 | Limits::default(), |
| 1377 | ); |
| 1378 | assert_eq!(terminal(&events).outcome, Outcome::Completed); |
| 1379 | assert_eq!(terminal(&events).created_count, 1); |
| 1380 | assert!(!s.0.join("output/folder").exists()); |
| 1381 | assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 1); |
| 1382 | } |
| 1383 | #[test] |
| 1384 | fn seven_zip_limits_truncation_and_existing_files_are_preserved() { |
| 1385 | let bytes = seven_fixture("lzma2.7z"); |
| 1386 | for cut in [0, 1, 6, 12, 31, 32, bytes.len() - 1] { |
| 1387 | let s = Scratch::new(); |
| 1388 | let events = extract( |
| 1389 | &s, |
| 1390 | &bytes[..cut], |
| 1391 | None, |
| 1392 | Selection::All, |
| 1393 | None, |
| 1394 | Limits::default(), |
| 1395 | ); |
| 1396 | assert_eq!(terminal(&events).outcome, Outcome::Failed); |
| 1397 | assert_eq!(terminal(&events).publication, Publication::None); |
| 1398 | assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 0); |
| 1399 | } |
| 1400 | let s = Scratch::new(); |
| 1401 | let events = extract( |
| 1402 | &s, |
| 1403 | &bytes, |
| 1404 | None, |
| 1405 | Selection::All, |
| 1406 | None, |
| 1407 | Limits { |
| 1408 | output: 100, |
| 1409 | ..Limits::default() |
| 1410 | }, |
| 1411 | ); |
| 1412 | assert_eq!(terminal(&events).error, ErrorCode::Limit); |
| 1413 | assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 0); |
| 1414 | fs::create_dir(s.0.join("output/folder")).unwrap(); |
| 1415 | #[cfg(unix)] |
| 1416 | { |
| 1417 | use std::os::unix::fs::PermissionsExt; |
| 1418 | fs::set_permissions(s.0.join("output/folder"), fs::Permissions::from_mode(0o700)).unwrap(); |
| 1419 | } |
| 1420 | fs::write(s.0.join("output/folder/hello.txt"), b"preserve").unwrap(); |
| 1421 | let events = extract(&s, &bytes, None, Selection::All, None, Limits::default()); |
| 1422 | assert_eq!(terminal(&events).error, ErrorCode::Conflict); |
| 1423 | assert_eq!( |
| 1424 | fs::read(s.0.join("output/folder/hello.txt")).unwrap(), |
| 1425 | b"preserve" |
| 1426 | ); |
| 1427 | let s = Scratch::new(); |
| 1428 | let events = extract( |
| 1429 | &s, |
| 1430 | &seven_fixture("bad-trailing.7z"), |
| 1431 | None, |
| 1432 | Selection::All, |
| 1433 | None, |
| 1434 | Limits::default(), |
| 1435 | ); |
| 1436 | assert_eq!(terminal(&events).error, ErrorCode::Integrity); |
| 1437 | assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 0); |
| 1438 | } |
| 1439 | #[test] |
| 1440 | fn seven_zip_parser_honors_cancellation_checkpoints() { |
| 1441 | let bytes = seven_fixture("long-match.7z"); |
| 1442 | let mut calls = 0; |
| 1443 | let result = archive::parse(&bytes, Limits::default(), true, &mut || { |
| 1444 | calls += 1; |
| 1445 | if calls >= 5 { |
| 1446 | Err(ErrorCode::None) |
| 1447 | } else { |
| 1448 | Ok(()) |
| 1449 | } |
| 1450 | }); |
| 1451 | assert!(matches!(result, Err(ErrorCode::None))); |
| 1452 | } |
| 1453 | #[test] |
| 1454 | fn pr64_malicious_corpus_is_rejected_without_writes() { |
| 1455 | let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")) |
| 1456 | .join("../../tests/malicious-archive-fixtures/fixtures"); |
| 1457 | let cases = [ |
| 1458 | ("zip-dotdot.zip", ErrorCode::UnsafePath, 131072, None), |
| 1459 | ( |
| 1460 | "zip-absolute-posix.zip", |
| 1461 | ErrorCode::UnsafePath, |
| 1462 | 131072, |
| 1463 | None, |
| 1464 | ), |
| 1465 | ( |
| 1466 | "zip-absolute-drive.zip", |
| 1467 | ErrorCode::UnsafePath, |
| 1468 | 131072, |
| 1469 | None, |
| 1470 | ), |
| 1471 | ( |
| 1472 | "zip-backslash-dotdot.zip", |
| 1473 | ErrorCode::UnsafePath, |
| 1474 | 131072, |
| 1475 | None, |
| 1476 | ), |
| 1477 | ("tar-dotdot.tar", ErrorCode::UnsafePath, 131072, None), |
| 1478 | ("targz-dotdot.tar.gz", ErrorCode::UnsafePath, 131072, None), |
| 1479 | ( |
| 1480 | "tar-absolute-posix.tar", |
| 1481 | ErrorCode::UnsafePath, |
| 1482 | 131072, |
| 1483 | None, |
| 1484 | ), |
| 1485 | ("zip-symlink-escape.zip", ErrorCode::Conflict, 131072, None), |
| 1486 | ("tar-symlink-escape.tar", ErrorCode::Conflict, 131072, None), |
| 1487 | ("zip-output-limit.zip", ErrorCode::Limit, 1024, None), |
| 1488 | ( |
| 1489 | "gzip-output-limit.gz", |
| 1490 | ErrorCode::Limit, |
| 1491 | 1024, |
| 1492 | Some("payload.bin"), |
| 1493 | ), |
| 1494 | ("targz-output-limit.tar.gz", ErrorCode::Limit, 1024, None), |
| 1495 | ( |
| 1496 | "zip-bad-local-header.zip", |
| 1497 | ErrorCode::Integrity, |
| 1498 | 131072, |
| 1499 | None, |
| 1500 | ), |
| 1501 | ("tar-bad-checksum.tar", ErrorCode::Integrity, 131072, None), |
| 1502 | ( |
| 1503 | "gzip-reserved-flags.gz", |
| 1504 | ErrorCode::Integrity, |
| 1505 | 131072, |
| 1506 | Some("payload.bin"), |
| 1507 | ), |
| 1508 | ]; |
| 1509 | for (name, expected, output, gzip) in cases { |
| 1510 | let s = Scratch::new(); |
| 1511 | let bytes = fs::read(root.join(name)).unwrap(); |
| 1512 | fs::write(s.0.join("outside.txt"), b"preserve").unwrap(); |
| 1513 | let events = extract( |
| 1514 | &s, |
| 1515 | &bytes, |
| 1516 | gzip, |
| 1517 | Selection::All, |
| 1518 | None, |
| 1519 | Limits { |
| 1520 | input: 1048576, |
| 1521 | output, |
| 1522 | entries: 64, |
| 1523 | }, |
| 1524 | ); |
| 1525 | assert_eq!( |
| 1526 | terminal(&events).outcome, |
| 1527 | Outcome::Failed, |
| 1528 | "{name}: {events:?}" |
| 1529 | ); |
| 1530 | assert_eq!(terminal(&events).error, expected, "{name}"); |
| 1531 | assert_eq!(terminal(&events).publication, Publication::None); |
| 1532 | assert_eq!(terminal(&events).created_count, 0); |
| 1533 | assert_eq!(terminal(&events).retained_partial_count, 0); |
| 1534 | assert!(!events.iter().any(|e| matches!(e, Message::Output { .. }))); |
| 1535 | assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 0); |
| 1536 | assert_eq!(fs::read(s.0.join("outside.txt")).unwrap(), b"preserve"); |
| 1537 | assert_eq!(fs::read(s.0.join("input")).unwrap(), bytes); |
| 1538 | } |
| 1539 | } |
| 1540 | #[cfg(target_os = "linux")] |
| 1541 | #[test] |
| 1542 | fn seven_zip_reference_reader_accepts_synthetic_fixtures() { |
| 1543 | let helper = PathBuf::from(env!("CARGO_MANIFEST_DIR")) |
| 1544 | .join("../../tests/rust-archive-worker/seven_zip_reference.py"); |
| 1545 | assert!( |
| 1546 | Command::new("python3") |
| 1547 | .arg(helper) |
| 1548 | .status() |
| 1549 | .unwrap() |
| 1550 | .success() |
| 1551 | ); |
| 1552 | } |
| 1553 | |
| 1554 | mod hardening; |
| 1555 | |
| 1556 | #[test] |
| 1557 | fn disk_full_error_tag_preserves_previous_tags_and_rejects_unknown() { |
| 1558 | for (tag, error) in [ |
| 1559 | ErrorCode::None, |
| 1560 | ErrorCode::Integrity, |
| 1561 | ErrorCode::UnsupportedFormat, |
| 1562 | ErrorCode::UnsupportedFeature, |
| 1563 | ErrorCode::WrongPassword, |
| 1564 | ErrorCode::UnsafePath, |
| 1565 | ErrorCode::Conflict, |
| 1566 | ErrorCode::Limit, |
| 1567 | ErrorCode::Io, |
| 1568 | ErrorCode::Protocol, |
| 1569 | ErrorCode::Internal, |
| 1570 | ErrorCode::SourceChanged, |
| 1571 | ErrorCode::InvalidRequest, |
| 1572 | ErrorCode::DiskFull, |
| 1573 | ] |
| 1574 | .into_iter() |
| 1575 | .enumerate() |
| 1576 | { |
| 1577 | let message = Message::Terminal(Terminal { |
| 1578 | outcome: Outcome::Failed, |
| 1579 | error, |
| 1580 | publication: Publication::None, |
| 1581 | created_count: 0, |
| 1582 | retained_partial_count: 0, |
| 1583 | durability: Durability::NotApplicable, |
| 1584 | cleanup: Cleanup::Complete, |
| 1585 | detail: String::new(), |
| 1586 | }); |
| 1587 | let mut bytes = Vec::new(); |
| 1588 | Writer::new(&mut bytes, 17).send(&message).unwrap(); |
| 1589 | assert_eq!(bytes[33], tag as u8); |
| 1590 | let decoded = Reader::new(bytes.as_slice()).read().unwrap().unwrap().2; |
| 1591 | assert_eq!(terminal(&[decoded]).error, error); |
| 1592 | bytes[33] = 14; |
| 1593 | assert!(Reader::new(bytes.as_slice()).read().is_err()); |
| 1594 | } |
| 1595 | } |
| 1596 | |
| 1597 | mod folder_inputs; |