Skip to content
Open
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
6 changes: 3 additions & 3 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 @@ -54,7 +54,7 @@ once_cell = "=1.21.3"
rayon = "=1.12.0"
tar = "=0.4.46"
flate2 = "=1.1.9"
zip = { version = "=8.6.0", default-features = false, features = ["deflate"] }
zip = { version = "=9.0.0", default-features = false, features = ["deflate"] }
fs2 = "=0.4.3"
same-file = "=1.0.6"
libc = "=0.2.182"
Expand Down
2 changes: 1 addition & 1 deletion crates/socket-patch-cli/tests/e2e_gradle_agent_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn patch_jar(jar: &[u8]) -> Vec<u8> {
let mut entry = archive.by_index(i).unwrap();
let mut buf = Vec::new();
entry.read_to_end(&mut buf).unwrap();
let name = entry.name().to_string();
let name = entry.name().unwrap().into_owned();
let buf = if name == NOTICE {
patched_notice()
} else if name == VICTIM_CLASS_MEMBER {
Expand Down
2 changes: 1 addition & 1 deletion crates/socket-patch-cli/tests/e2e_nuget_dotnet_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ fn patched_nupkg(upstream: &[u8], patched: &[u8]) -> Vec<u8> {
let mut replaced = false;
for i in 0..archive.len() {
let mut f = archive.by_index(i).unwrap();
let name = f.name().to_string();
let name = f.name().unwrap().into_owned();
if name == ".signature.p7s" || f.is_dir() {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions crates/socket-patch-cli/tests/e2e_redirect_gradle_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ fn patched_jar() -> Vec<u8> {
let mut entry = archive.by_index(i).unwrap();
let mut buf = Vec::new();
entry.read_to_end(&mut buf).unwrap();
let name = entry.name().to_string();
let name = entry.name().unwrap().into_owned();
let buf = if name == NOTICE {
patched_notice()
} else if name == VICTIM_CLASS_MEMBER {
Expand Down Expand Up @@ -1543,7 +1543,7 @@ fn served_consumer() -> Served {
let mut entry = archive.by_index(i).unwrap();
let mut buf = Vec::new();
entry.read_to_end(&mut buf).unwrap();
members.push((entry.name().to_string(), buf));
members.push((entry.name().unwrap().into_owned(), buf));
}
members.push((CONSUMER_PATCHED_MEMBER.to_string(), b"patched\n".to_vec()));
let upstream_pom = central_file(&repo_path(CONSUMER, CONSUMER_VERSION, None, "pom"));
Expand Down
4 changes: 2 additions & 2 deletions crates/socket-patch-cli/tests/gradle_agent_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn service_jar() -> Vec<u8> {
let mut entry = archive.by_index(i).unwrap();
let mut buf = Vec::new();
entry.read_to_end(&mut buf).unwrap();
let name = entry.name().to_string();
let name = entry.name().unwrap().into_owned();
let buf = if name == NOTICE {
b"patched\n".to_vec()
} else {
Expand Down Expand Up @@ -1132,7 +1132,7 @@ fn tampered_service_jar_writes_nothing() {
let mut entry = honest.by_index(i).unwrap();
let mut buf = Vec::new();
entry.read_to_end(&mut buf).unwrap();
tampered.start_file(entry.name(), opts).unwrap();
tampered.start_file(entry.name().unwrap(), opts).unwrap();
tampered.write_all(&buf).unwrap();
}
if symlink_mode {
Expand Down
2 changes: 1 addition & 1 deletion crates/socket-patch-cli/tests/maven_build_common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ pub fn jar_with_member(jar: &[u8], name: &str, bytes: &[u8]) -> Vec<u8> {
let mut replaced = false;
for i in 0..archive.len() {
let mut entry = archive.by_index(i).unwrap();
let entry_name = entry.name().to_string();
let entry_name = entry.name().unwrap().into_owned();
if entry.is_dir() {
writer.add_directory(entry_name, opts).unwrap();
continue;
Expand Down
2 changes: 1 addition & 1 deletion crates/socket-patch-cli/tests/maven_production/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ fn members(jar: &[u8], what: &str) -> BTreeMap<String, Vec<u8>> {
}
let mut bytes = Vec::new();
entry.read_to_end(&mut bytes).unwrap();
out.insert(entry.name().to_string(), bytes);
out.insert(entry.name().unwrap().into_owned(), bytes);
}
out
}
Expand Down
3 changes: 2 additions & 1 deletion crates/socket-patch-cli/tests/vendor/vendor_failure_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,8 @@ fn rezip(whl: &[u8]) -> Vec<u8> {
let mut entry = src.by_index(i).unwrap();
let mut bytes = Vec::new();
entry.read_to_end(&mut bytes).unwrap();
out.start_file(entry.name().to_string(), opts).unwrap();
out.start_file(entry.name().unwrap().into_owned(), opts)
.unwrap();
out.write_all(&bytes).unwrap();
}
let alt = out.finish().unwrap().into_inner();
Expand Down
2 changes: 1 addition & 1 deletion crates/socket-patch-cli/tests/vex_pdm_hatch_common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ pub fn tamper_wheel(cwd: &Path) {
let mut saw_module = false;
for i in 0..archive.len() {
let mut member = archive.by_index(i).unwrap();
let name = member.name().to_string();
let name = member.name().unwrap().into_owned();
let mut bytes = Vec::new();
member.read_to_end(&mut bytes).unwrap();
if name == MODULE {
Expand Down
2 changes: 1 addition & 1 deletion crates/socket-patch-cli/tests/vex_pipenv_pip_common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ pub fn tamper_wheel(cwd: &Path) {
let mut saw_module = false;
for i in 0..archive.len() {
let mut member = archive.by_index(i).unwrap();
let name = member.name().to_string();
let name = member.name().unwrap().into_owned();
let mut bytes = Vec::new();
member.read_to_end(&mut bytes).unwrap();
if name == MODULE {
Expand Down
1 change: 1 addition & 0 deletions crates/socket-patch-core/src/hosted/wheel_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ fn parse_wheel_record(bytes: &[u8]) -> Option<WheelRecord> {
let mut archive = zip::ZipArchive::new(std::io::Cursor::new(bytes)).ok()?;
// The wheel's own dist-info sits at the root, never nested.
let dist_info = archive.file_names().find_map(|name| {
let name = name.ok()?;
let stem = name.strip_suffix("/RECORD")?;
(stem.ends_with(".dist-info") && !stem.contains('/')).then(|| stem.to_string())
})?;
Expand Down
5 changes: 3 additions & 2 deletions crates/socket-patch-core/src/patch/jar_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ pub(crate) mod fixture {
let opts = zip::write::SimpleFileOptions::default();
for i in 0..zip.len() {
let mut entry = zip.by_index(i).unwrap();
let name = entry.name().to_string();
let name = entry.name().unwrap().into_owned();
if name.ends_with('/') || !keep(&name) {
continue;
}
Expand Down Expand Up @@ -628,7 +628,8 @@ mod tests {
fn the_fixture_is_a_resigned_jar() {
let names = |jar: &[u8]| -> Vec<String> {
let zip = zip::ZipArchive::new(std::io::Cursor::new(jar)).unwrap();
let mut names: Vec<String> = zip.file_names().map(str::to_string).collect();
let mut names: Vec<String> =
zip.file_names().map(|n| n.unwrap().into_owned()).collect();
names.retain(|n| n.starts_with("META-INF/") && !n.ends_with('/'));
names.sort();
names
Expand Down
11 changes: 8 additions & 3 deletions crates/socket-patch-core/src/patch/jar_members.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ impl<R: Read + Seek> Jar<R> {
mut each: impl FnMut(&[u8], usize),
) -> Result<(), JarError> {
for index in 0..self.zip.len() {
let decoded = self.zip.name_for_index(index);
// A name the reader cannot decode is read raw below.
let decoded = self.zip.name_for_index(index).and_then(Result::ok);
if let Some(name) = decoded.filter(|name| self.zip.index_for_name(name) == Some(index))
{
if !name.ends_with('/') {
Expand Down Expand Up @@ -291,7 +292,11 @@ impl<R: Read + Seek> Jar<R> {
/// Whether the jar holds a signature file (`META-INF/*.SF`, `.RSA`,
/// `.DSA`, `.EC`).
pub(crate) fn has_signature_file(&self) -> bool {
self.zip.file_names().any(crate::vendor::jvm::is_signature)
// A name the reader cannot decode counts as one: the signed jar's
// checks are the stricter path.
self.zip
.file_names()
.any(|name| name.map_or(true, |name| crate::vendor::jvm::is_signature(&name)))
}

/// Inflate the member `name` into `sink`, within the pass's budget.
Expand Down Expand Up @@ -1030,7 +1035,7 @@ mod tests {
let decoded: Vec<String> = zip::ZipArchive::new(std::io::Cursor::new(&bytes))
.unwrap()
.file_names()
.map(str::to_string)
.map(|n| n.unwrap().into_owned())
.collect();
assert!(!decoded.iter().any(|name| name == NAME), "{decoded:?}");
let mut jar = Jar::of_bytes(&bytes).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions crates/socket-patch-core/src/vendor/berry_zip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ mod tests {
let zip_bytes = rebuild_cache_zip(&tgz, "@scope/pkg").unwrap();
let mut zip = zip::ZipArchive::new(std::io::Cursor::new(zip_bytes)).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().into_owned())
.collect();
assert_eq!(
names,
Expand All @@ -508,7 +508,7 @@ mod tests {
entry.compression(),
zip::CompressionMethod::Stored,
"{}: every entry stored (the c0)",
entry.name()
entry.name().unwrap()
);
}
}
Expand Down
3 changes: 2 additions & 1 deletion crates/socket-patch-core/src/vendor/pypi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12769,7 +12769,8 @@ wheels = [{url = "https://files.pythonhosted.org/six.whl", hash = "sha256:upstre
let mut entry = src.by_index(i).unwrap();
let mut bytes = Vec::new();
entry.read_to_end(&mut bytes).unwrap();
out.start_file(entry.name().to_string(), opts).unwrap();
out.start_file(entry.name().unwrap().into_owned(), opts)
.unwrap();
out.write_all(&bytes).unwrap();
}
let alt = out.finish().unwrap().into_inner();
Expand Down
2 changes: 1 addition & 1 deletion crates/socket-patch-core/src/vendor/pypi_uv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2375,7 +2375,7 @@ pub(super) fn wheel_metadata_text(bytes: &[u8]) -> Option<String> {
let mut metadata_name: Option<String> = None;
for i in 0..archive.len() {
let entry = archive.by_index(i).ok()?;
let name = entry.name();
let name = entry.name().ok()?;
// A wheel's metadata lives at `<dist>-<ver>.dist-info/METADATA`, one
// level below the root — never nested inside another directory.
if let Some(stem) = name.strip_suffix("/METADATA") {
Expand Down
20 changes: 16 additions & 4 deletions crates/socket-patch-core/src/vendor/registry_fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,13 @@ fn plan_zip(
if file.is_dir() {
continue;
}
let raw = PathBuf::from(file.name());
let raw = match file.name() {
Ok(name) => PathBuf::from(name.as_ref()),
Err(e) => {
plan.header_refusal = Some((i, format!("unreadable zip entry name: {e}")));
break;
}
};
let rel = if strip_first {
match strip_first_component(&raw) {
Some(rel) => rel,
Expand Down Expand Up @@ -837,7 +843,10 @@ pub(crate) fn go_h1_of_zip(bytes: &[u8]) -> Result<String, String> {
if file.is_dir() {
continue; // go module zips carry files only
}
let name = file.name().to_string();
let name = file
.name()
.map_err(|e| format!("unreadable module zip entry name: {e}"))?
.into_owned();
if name.contains('\n') {
return Err("module zip entry name contains a newline".to_string());
}
Expand Down Expand Up @@ -947,7 +956,10 @@ pub(crate) fn extract_zip_with_prefix_skipping(
if file.is_dir() {
continue;
}
let name = file.name().to_string();
let name = file
.name()
.map_err(|e| format!("unreadable module zip entry name: {e}"))?
.into_owned();
let Some(rel) = name.strip_prefix(prefix) else {
return Err(format!(
"module zip entry `{name}` lies outside `{prefix}` — refusing the artifact"
Expand Down Expand Up @@ -2540,7 +2552,7 @@ mod tests {
if file.is_dir() {
continue;
}
let name = file.name().to_string();
let name = file.name().unwrap().into_owned();
// `tree_of` reads no mode off a non-Unix disk (it reports 0),
// so the oracle expects none there either.
let mode = if !cfg!(unix) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ fn jar_members(jar: &[u8]) -> Result<BTreeMap<String, Vec<u8>>, String> {
}
let mut bytes = Vec::new();
entry.read_to_end(&mut bytes).map_err(|e| e.to_string())?;
members.insert(entry.name().to_string(), bytes);
members.insert(entry.name().unwrap().into_owned(), bytes);
}
Ok(members)
}
Expand Down
9 changes: 5 additions & 4 deletions crates/socket-patch-core/src/vendor/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -937,11 +937,12 @@ fn read_zip_within<R: Read + std::io::Seek>(
let mut entry = zip.by_index(i).map_err(|_| ZipError::Unreadable)?;
if strict {
let non_canonical = || ZipError::NonCanonical;
if entry.is_symlink() || entry.name().starts_with('/') {
let name = entry.name().map_err(|_| ZipError::Unreadable)?;
if entry.is_symlink() || name.starts_with('/') {
return Err(non_canonical());
}
let key = crate::patch::package::canonical_member_key(entry.name())
.ok_or_else(non_canonical)?;
let key =
crate::patch::package::canonical_member_key(&name).ok_or_else(non_canonical)?;
// Directories share the key space: a dir `six.py/` next to a
// file `SIX.py` collides on disk too.
if !seen.insert(key) {
Expand All @@ -966,7 +967,7 @@ fn read_zip_within<R: Read + std::io::Seek>(
};
return Err(ZipError::TooLarge(budget.exceeded(unpacked)));
}
let name = entry.name().to_string();
let name = entry.name().map_err(|_| ZipError::Unreadable)?.into_owned();
let mut bytes = Vec::new();
// +1 so an entry that would exceed the remaining budget reads one
// byte past it and is rejected, rather than truncating silently.
Expand Down
Loading