pub struct ZipEntry {
pub name: String,
pub compressed_size: u64,
pub uncompressed_size: u64,
pub compression_method: u16,
pub offset: u64,
}Expand description
Entry in the ZIP central directory
Fields§
§name: String§compressed_size: u64§uncompressed_size: u64§compression_method: u16§offset: u64Implementations§
Source§impl ZipEntry
impl ZipEntry
Sourcepub fn safe_path(&self) -> PathBuf
pub fn safe_path(&self) -> PathBuf
Return a sanitized extraction path that is safe against zip-slip attacks.
Strips:
- Leading
/and\(absolute paths) - Any
..components (parent directory traversal) - Windows drive prefixes (e.g.
C:)
// A malicious entry name like "../../../etc/passwd" becomes "etc/passwd"Always use this method when extracting entries to disk. Never use
entry.name directly as a filesystem path.
§Example
let mut reader = StreamingZipReader::open("archive.zip")?;
let output_dir = std::path::Path::new("./output");
for entry in reader.entries() {
let dest = output_dir.join(entry.safe_path());
// dest is guaranteed to be inside output_dir
}Trait Implementations§
Auto Trait Implementations§
impl Freeze for ZipEntry
impl RefUnwindSafe for ZipEntry
impl Send for ZipEntry
impl Sync for ZipEntry
impl Unpin for ZipEntry
impl UnsafeUnpin for ZipEntry
impl UnwindSafe for ZipEntry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more