Struct zip::unstable::stream::ZipStreamFileMetadata
source · pub struct ZipStreamFileMetadata(/* private fields */);
Expand description
Additional metadata for the file.
Implementations§
source§impl ZipStreamFileMetadata
impl ZipStreamFileMetadata
sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
Get the name of the file
§Warnings
It is dangerous to use this name directly when extracting an archive.
It may contain an absolute path (/etc/shadow
), or break out of the
current directory (../runtime
). Carelessly writing to these paths
allows an attacker to craft a ZIP archive that will overwrite critical
files.
You can use the ZipFile::enclosed_name
method to validate the name
as a safe path.
sourcepub fn name_raw(&self) -> &[u8] ⓘ
pub fn name_raw(&self) -> &[u8] ⓘ
Get the name of the file, in the raw (internal) byte representation.
The encoding of this data is currently undefined.
sourcepub fn mangled_name(&self) -> PathBuf
pub fn mangled_name(&self) -> PathBuf
Rewrite the path, ignoring any path components with special meaning.
- Absolute paths are made relative
- std::path::Component::ParentDirs are ignored
- Truncates the filename at a NULL byte
This is appropriate if you need to be able to extract something from
any archive, but will easily misrepresent trivial paths like
foo/../bar
as foo/bar
(instead of bar
). Because of this,
ZipFile::enclosed_name
is the better option in most scenarios.
sourcepub fn enclosed_name(&self) -> Option<PathBuf>
pub fn enclosed_name(&self) -> Option<PathBuf>
Ensure the file path is safe to use as a Path
.
- It can’t contain NULL bytes
- It can’t resolve to a path outside the current directory
foo/../bar
is fine,foo/../../bar
is not. - It can’t be an absolute path
This will read well-formed ZIP files correctly, and is resistant
to path-based exploits. It is recommended over
ZipFile::mangled_name
.
sourcepub fn data_start(&self) -> u64
pub fn data_start(&self) -> u64
Get the starting offset of the data of the compressed file