diff --git a/Cargo.lock b/Cargo.lock index dddf37d..6784769 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -236,7 +236,7 @@ dependencies = [ "uuid", "walkdir", "wiremock", - "zip 8.6.0", + "zip 9.1.2", "zstd 0.14.3", ] @@ -1255,6 +1255,18 @@ version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" +[[package]] +name = "nix" +version = "0.31.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf20d2fde8ff38632c426f1165ed7436270b44f199fc55284c38276f9db47c3d" +dependencies = [ + "bitflags 2.13.0", + "cfg-if", + "cfg_aliases", + "libc", +] + [[package]] name = "nom" version = "7.1.3" @@ -2172,7 +2184,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" dependencies = [ "fastrand", - "getrandom 0.3.4", + "getrandom 0.4.2", "once_cell", "rustix", "windows-sys 0.61.2", @@ -2461,6 +2473,12 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e28f89b80c87b8fb0cf04ab448d5dd0dd0ade2f8891bae878de66a75a28600e" +[[package]] +name = "typed-path" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce898823d8cd0f028662d2f349694b1af0a5cc9be83f1d213a00d3147445e1e" + [[package]] name = "typenum" version = "1.20.1" @@ -3135,23 +3153,26 @@ dependencies = [ "flate2", "indexmap", "memchr", - "typed-path", + "typed-path 0.12.3", "zopfli", ] [[package]] name = "zip" -version = "8.6.0" +version = "9.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d04a6b5381502aa6087c94c669499eb1602eb9c5e8198e534de571f7154809b" +checksum = "ec2e3161de27091f18a831d9494e9c53378a34833af5c1dda35ad85849da18d6" dependencies = [ "crc32fast", "flate2", + "getrandom 0.4.2", "indexmap", "memchr", - "typed-path", + "nix", + "typed-path 0.13.0", + "windows-sys 0.61.2", "zopfli", - "zstd 0.13.3", + "zstd 0.14.3", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index bb7efb7..2f9bca8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -136,7 +136,7 @@ plist = "1" # Compression — zstd is the wire format (level 9–11 typical); zip writes archives with Z_STANDARD entries zstd = { version = "0.14", features = ["zstdmt"] } -zip = { version = "8", default-features = false, features = ["zstd", "deflate"] } +zip = { version = "9", default-features = false, features = ["zstd", "deflate"] } # gzip — `.xcactivitylog` build logs are gzip of an SLF0 token stream. Already # in the dependency tree via `zip`/`reqwest`, so this direct dep adds no new diff --git a/src/cli/xcode.rs b/src/cli/xcode.rs index cd8f809..725f459 100644 --- a/src/cli/xcode.rs +++ b/src/cli/xcode.rs @@ -3397,7 +3397,7 @@ mod tests { .expect("a PUT to the presigned URL"); let mut archive_zip = ZipArchive::new(std::io::Cursor::new(put.body.clone())).unwrap(); let names: Vec = (0..archive_zip.len()) - .map(|i| archive_zip.by_index(i).unwrap().name().to_string()) + .map(|i| archive_zip.by_index(i).unwrap().name().unwrap().to_string()) .collect(); assert_eq!(names, vec!["dependencies.json"]); let mut content = String::new(); @@ -3513,7 +3513,7 @@ mod tests { .expect("a PUT to the presigned URL"); let mut archive_zip = ZipArchive::new(std::io::Cursor::new(put.body.clone())).unwrap(); let names: Vec = (0..archive_zip.len()) - .map(|i| archive_zip.by_index(i).unwrap().name().to_string()) + .map(|i| archive_zip.by_index(i).unwrap().name().unwrap().to_string()) .collect(); assert_eq!(names, vec!["timings.json"]); let mut content = String::new(); @@ -3626,7 +3626,7 @@ mod tests { .expect("an artefact PUT"); let mut zip = ZipArchive::new(std::io::Cursor::new(art.body.clone())).unwrap(); let names: Vec = (0..zip.len()) - .map(|i| zip.by_index(i).unwrap().name().to_string()) + .map(|i| zip.by_index(i).unwrap().name().unwrap().to_string()) .collect(); assert_eq!(names.len(), 1); assert!(names[0].ends_with(".ipa"), "artefact entry: {}", names[0]); @@ -3644,7 +3644,7 @@ mod tests { assert!( inner .file_names() - .any(|n| n.starts_with("Payload/MyApp.app/")), + .any(|n| n.is_ok_and(|n| n.starts_with("Payload/MyApp.app/"))), "synthetic .ipa must place the app under Payload/" ); } diff --git a/src/cli/xcode_ipa.rs b/src/cli/xcode_ipa.rs index c2c88a0..e6e4bb2 100644 --- a/src/cli/xcode_ipa.rs +++ b/src/cli/xcode_ipa.rs @@ -393,6 +393,53 @@ mod tests { assert_eq!(main_executable_uuid(&app), Some(expected)); } + /// Pins the permission bits, timestamp and flags of the synthetic `.ipa` + /// entries (captured from zip 8.6.0, unchanged under zip 9). + #[cfg(unix)] + #[test] + fn ipa_entry_metadata_is_pinned() { + use std::os::unix::fs::PermissionsExt; + let td = tempfile::tempdir().unwrap(); + let app = make_app(td.path(), "MyApp.app"); + std::fs::set_permissions(app.join("MyApp"), std::fs::Permissions::from_mode(0o755)) + .unwrap(); + std::fs::set_permissions(app.join("icon.png"), std::fs::Permissions::from_mode(0o644)) + .unwrap(); + let ipa = td.path().join("MyApp.ipa"); + package_app_as_ipa(&app, &ipa).unwrap(); + + let mut zip = ZipArchive::new(std::fs::File::open(&ipa).unwrap()).unwrap(); + for (name, mode, method) in [ + ( + "Payload/MyApp.app/MyApp", + 0o100755, + CompressionMethod::Deflated, + ), + ( + "Payload/MyApp.app/icon.png", + 0o100644, + CompressionMethod::Stored, + ), + ] { + let e = zip.by_name(name).unwrap(); + assert_eq!(e.unix_mode(), Some(mode), "{name}: unix mode"); + assert_eq!(e.compression(), method, "{name}: method"); + let t = e.last_modified().expect("mtime"); + assert_eq!( + ( + t.year(), + t.month(), + t.day(), + t.hour(), + t.minute(), + t.second() + ), + (1980, 1, 1, 0, 0, 0), + "{name}: fixed mtime" + ); + } + } + #[test] fn packages_app_under_payload_with_per_file_method() { let td = tempfile::tempdir().unwrap(); @@ -402,7 +449,7 @@ mod tests { let mut zip = ZipArchive::new(std::fs::File::open(&ipa).unwrap()).unwrap(); let names: Vec = (0..zip.len()) - .map(|i| zip.by_index(i).unwrap().name().to_string()) + .map(|i| zip.by_index(i).unwrap().name().unwrap().to_string()) .collect(); assert!(names.contains(&"Payload/MyApp.app/Info.plist".to_string())); assert!(names.contains(&"Payload/MyApp.app/MyApp".to_string())); @@ -468,7 +515,7 @@ mod tests { package_app_as_ipa(&app, &ipa).unwrap(); let mut zip = ZipArchive::new(std::fs::File::open(&ipa).unwrap()).unwrap(); let names: Vec = (0..zip.len()) - .map(|i| zip.by_index(i).unwrap().name().to_string()) + .map(|i| zip.by_index(i).unwrap().name().unwrap().to_string()) .collect(); assert!(!names.iter().any(|n| n.ends_with("/Current"))); } diff --git a/src/compress/mod.rs b/src/compress/mod.rs index 176e5a9..16923fe 100644 --- a/src/compress/mod.rs +++ b/src/compress/mod.rs @@ -250,7 +250,7 @@ mod tests { // Iteration order matches insertion order. let names: Vec = (0..archive.len()) - .map(|i| archive.by_index(i).unwrap().name().to_string()) + .map(|i| archive.by_index(i).unwrap().name().unwrap().to_string()) .collect(); assert_eq!(names, vec!["mapping.txt", "icon.png"]); @@ -271,6 +271,86 @@ mod tests { assert_eq!(icon_bytes, b"\x89PNG\r\n\x1a\n"); } + /// Pins the raw header bytes of every archive we write, so a `zip` upgrade + /// that changes a default (timestamps, flags, version fields, extra + /// fields, unix mode, ZIP64, data descriptors, comment) fails here instead + /// of silently changing the wire format. Values were captured from the + /// archives written by zip 8.6.0 and verified byte-identical under zip 9. + #[test] + fn written_archive_headers_are_pinned() { + let u16_at = |b: &[u8], o: usize| u16::from_le_bytes([b[o], b[o + 1]]); + let u32_at = |b: &[u8], o: usize| u32::from_le_bytes([b[o], b[o + 1], b[o + 2], b[o + 3]]); + + let dir = tempfile::tempdir().unwrap(); + let stored = dir.path().join("a.apk"); + let mapped = dir.path().join("mapping.txt"); + let out = dir.path().join("packed.zip"); + std::fs::write(&stored, b"stored payload").unwrap(); + std::fs::write(&mapped, b"class a -> b:\n".repeat(64)).unwrap(); + pack_entries( + &[ + ZipEntry::stored("a.apk", &stored), + ZipEntry::compressed("mapping.txt", &mapped), + ], + &out, + Strategy::Zstd(11), + ) + .unwrap(); + let b = std::fs::read(&out).unwrap(); + + // (name, version needed, method) for each entry, in insertion order. + let expect = [("a.apk", 10u16, 0u16), ("mapping.txt", 45, 93)]; + let mut p = 0; + for (name, ver, method) in expect { + assert_eq!(&b[p..p + 4], b"PK\x03\x04"); + assert_eq!(u16_at(&b, p + 4), ver, "{name}: version needed"); + assert_eq!( + u16_at(&b, p + 6), + 0, + "{name}: flags (no UTF-8 bit, no descriptor)" + ); + assert_eq!(u16_at(&b, p + 8), method, "{name}: method"); + assert_eq!(u16_at(&b, p + 10), 0, "{name}: DOS time"); + assert_eq!(u16_at(&b, p + 12), 33, "{name}: DOS date 1980-01-01"); + let (csize, nlen, elen) = ( + u32_at(&b, p + 18) as usize, + u16_at(&b, p + 26) as usize, + u16_at(&b, p + 28) as usize, + ); + assert_eq!(&b[p + 30..p + 30 + nlen], name.as_bytes()); + assert_eq!(elen, 0, "{name}: no local extra field"); + p += 30 + nlen + elen + csize; + } + for (name, ver, method) in expect { + assert_eq!(&b[p..p + 4], b"PK\x01\x02"); + // The made-by host byte is platform-dependent in the zip crate + // (DOS on Windows, Unix elsewhere) when not set explicitly. + let host: u16 = if cfg!(windows) { 0x000 } else { 0x300 }; + assert_eq!( + u16_at(&b, p + 4), + host | ver, + "{name}: made-by host/version" + ); + assert_eq!(u16_at(&b, p + 6), ver); + assert_eq!(u16_at(&b, p + 8), 0); + assert_eq!(u16_at(&b, p + 10), method); + assert_eq!(u16_at(&b, p + 12), 0); + assert_eq!(u16_at(&b, p + 14), 33); + let (nlen, elen, clen) = ( + u16_at(&b, p + 28) as usize, + u16_at(&b, p + 30) as usize, + u16_at(&b, p + 32) as usize, + ); + assert_eq!((elen, clen), (0, 0), "{name}: no extra/comment"); + assert_eq!(u32_at(&b, p + 38), 0o100644 << 16, "{name}: unix mode 0644"); + p += 46 + nlen + elen + clen; + } + assert_eq!(&b[p..p + 4], b"PK\x05\x06"); + assert_eq!(u16_at(&b, p + 10), 2, "entry count"); + assert_eq!(u16_at(&b, p + 20), 0, "no archive comment"); + assert_eq!(b.len(), p + 22, "no trailing bytes / ZIP64 records"); + } + #[test] fn stored_entry_uses_method_zero_and_mixes_with_zstd() { let dir = tempfile::tempdir().unwrap(); diff --git a/src/symbols/elf.rs b/src/symbols/elf.rs index 06ab364..a48e8d9 100644 --- a/src/symbols/elf.rs +++ b/src/symbols/elf.rs @@ -109,7 +109,11 @@ pub fn extract_libs( if !entry.is_file() { continue; } - let name = entry.name().to_string(); + // zip 9: `name()` returns a Result (defensive; decoding falls back to CP437). + let name = entry + .name() + .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))? + .into_owned(); if !(is_native_lib_entry(&name) || extra.matches(&name)) { continue; } diff --git a/src/upload/build_info.rs b/src/upload/build_info.rs index 31a884f..11aa177 100644 --- a/src/upload/build_info.rs +++ b/src/upload/build_info.rs @@ -384,7 +384,7 @@ mod tests { .expect("a PUT to the presigned URL"); let mut archive = ZipArchive::new(std::io::Cursor::new(put.body.clone())).unwrap(); let names: Vec = (0..archive.len()) - .map(|i| archive.by_index(i).unwrap().name().to_string()) + .map(|i| archive.by_index(i).unwrap().name().unwrap().to_string()) .collect(); assert_eq!(names, vec!["dependencies.json", "timings.json"]); { diff --git a/tests/file_handling.rs b/tests/file_handling.rs index 05e1bf1..c707698 100644 --- a/tests/file_handling.rs +++ b/tests/file_handling.rs @@ -42,7 +42,7 @@ fn zip_entries(zip_bytes: &[u8]) -> Vec<(String, Vec)> { let mut e = archive.by_index(i).unwrap(); let mut data = Vec::new(); e.read_to_end(&mut data).unwrap(); // verifies the CRC - (e.name().to_string(), data) + (e.name().unwrap().to_string(), data) }) .collect() } diff --git a/tests/upload_build_info.rs b/tests/upload_build_info.rs index 63e9aa5..986ad69 100644 --- a/tests/upload_build_info.rs +++ b/tests/upload_build_info.rs @@ -54,7 +54,7 @@ fn dry_run_writes_bundle_and_exits_zero() { // The written bundle contains exactly the two sidecars. let mut archive = ZipArchive::new(std::fs::File::open(&out).unwrap()).unwrap(); let names: Vec = (0..archive.len()) - .map(|i| archive.by_index(i).unwrap().name().to_string()) + .map(|i| archive.by_index(i).unwrap().name().unwrap().to_string()) .collect(); assert_eq!(names, vec!["dependencies.json", "timings.json"]); let mut got = String::new();