Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/cli/xcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = (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();
Expand Down Expand Up @@ -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<String> = (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();
Expand Down Expand Up @@ -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<String> = (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]);
Expand All @@ -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/"
);
}
Expand Down
51 changes: 49 additions & 2 deletions src/cli/xcode_ipa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -402,7 +449,7 @@ mod tests {

let mut zip = ZipArchive::new(std::fs::File::open(&ipa).unwrap()).unwrap();
let names: Vec<String> = (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()));
Expand Down Expand Up @@ -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<String> = (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")));
}
Expand Down
82 changes: 81 additions & 1 deletion src/compress/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ mod tests {

// Iteration order matches insertion order.
let names: Vec<String> = (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"]);

Expand All @@ -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();
Expand Down
6 changes: 5 additions & 1 deletion src/symbols/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/upload/build_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = (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"]);
{
Expand Down
2 changes: 1 addition & 1 deletion tests/file_handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn zip_entries(zip_bytes: &[u8]) -> Vec<(String, Vec<u8>)> {
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()
}
Expand Down
2 changes: 1 addition & 1 deletion tests/upload_build_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = (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();
Expand Down
Loading