Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix CI with platform-dependent string encoding #125

Closed
wants to merge 2 commits into from
Closed
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
27 changes: 25 additions & 2 deletions src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@
use crate::zipcrypto::{ZipCryptoReader, ZipCryptoReaderValid, ZipCryptoValidator};
use indexmap::IndexMap;
use std::borrow::Cow;
use std::ffi::{OsStr, OsString};
use std::ffi::OsString;
use std::fs::create_dir_all;
use std::io::{self, copy, prelude::*, sink};
use std::ops::Deref;
use std::path::{Path, PathBuf};
use std::sync::{Arc, OnceLock};

#[cfg(unix)]
use std::os::unix::ffi::OsStringExt;
#[cfg(windows)]
use std::os::windows::ffi::OsStringExt;

#[cfg(any(
feature = "deflate",
feature = "deflate-zlib",
Expand Down Expand Up @@ -686,10 +691,28 @@
if let Some(p) = outpath.parent() {
Self::make_writable_dir_all(p)?;
}
/* FIXME: what bug does this code fix?
Dismissed Show dismissed Hide dismissed
* https://github.com/zip-rs/zip2/commit/8715d936cbd3e0fdc2e778b70d8a02e2dfc16fc2
* doesn't specify! */
Comment on lines +694 to +696
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/* FIXME: what bug does this code fix?
* https://github.com/zip-rs/zip2/commit/8715d936cbd3e0fdc2e778b70d8a02e2dfc16fc2
* doesn't specify! */
// Extract symlinks as symlinks

The bug was that symlinks were extracted as normal files.

if file.is_symlink() && (cfg!(unix) || cfg!(windows)) {
let mut target = Vec::with_capacity(file.size() as usize);
file.read_exact(&mut target)?;
let target_path: PathBuf = directory.as_ref().join(OsString::try_from(target)?);
#[cfg(unix)]
let target_str = OsString::from_vec(target);
#[cfg(windows)]
let target_str: OsString = {
let chunks = target.chunks_exact(2);
assert!(
chunks.remainder().is_empty(),
"windows utf-16 strings should be divisible by 2"
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't symlinks stored in UTF-8, given the general principle that file paths are Unix-style? The APPNOTE doesn't specifically address this.

let target_wide: Vec<u16> = chunks
.into_iter()
.map(|c| u16::from_le_bytes(c.try_into().unwrap()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will panic if a character code point is above 0xFFFF, because that has to be encoded in UTF-16 as a surrogate pair.

.collect();
OsString::from_wide(&target_wide)
};
let target_path: PathBuf = directory.as_ref().join(target_str);
#[cfg(unix)]
{
std::os::unix::fs::symlink(target_path, outpath.as_path())?;
Expand Down Expand Up @@ -1188,7 +1211,7 @@
/// `foo/../bar` as `foo/bar` (instead of `bar`). Because of this,
/// [`ZipFile::enclosed_name`] is the better option in most scenarios.
///
/// [`ParentDir`]: `Component::ParentDir`

Check warning on line 1214 in src/read.rs

View workflow job for this annotation

GitHub Actions / style_and_docs (--no-default-features)

unresolved link to `Component::ParentDir`

Check warning on line 1214 in src/read.rs

View workflow job for this annotation

GitHub Actions / style_and_docs (--all-features)

unresolved link to `Component::ParentDir`

Check warning on line 1214 in src/read.rs

View workflow job for this annotation

GitHub Actions / style_and_docs

unresolved link to `Component::ParentDir`
pub fn mangled_name(&self) -> PathBuf {
self.data.file_name_sanitized()
}
Expand Down
3 changes: 1 addition & 2 deletions tests/repro_old423.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use tempdir::TempDir;

#[cfg(all(unix, feature = "_deflate-any"))]
#[test]
fn repro_old423() -> zip::result::ZipResult<()> {
use std::io;
use tempdir::TempDir;
use zip::ZipArchive;

let mut v = Vec::new();
Expand Down
Loading