Skip to content

Commit

Permalink
make path join much more complicated for no reason
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmicexplorer committed May 15, 2024
1 parent 78297c6 commit aef0bb6
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@ use crate::types::{AesMode, AesVendorVersion, DateTime, System, ZipFileData};
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 @@ -689,7 +694,22 @@ impl<R: Read + Seek> ZipArchive<R> {
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"
);
let target_wide: Vec<u16> = chunks
.into_iter()
.map(|c| u16::from_le_bytes(c.try_into().unwrap()))
.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

0 comments on commit aef0bb6

Please sign in to comment.