
Cloud Vulnerability DB
A community-led vulnerabilities database
In src/read/extract.rs, the create_outfile function opens destination files using truncate(true) without unlinking pre-existing hardlinks and without enforcing O_NOFOLLOW on Unix platforms. When extracting an archive into a directory containing an existing hardlink, the target file outside the destination directory is truncated and overwritten with archive contents.
In src/read/extract.rs, the function create_outfile checks whether outpath is a symbolic link using std::fs::symlink_metadata. If so, it removes the file. However, it does not handle hard links, nor does it pass libc::O_NOFOLLOW on Unix platforms:
// src/read/extract.rs:304-325
if let Ok(meta) = std::fs::symlink_metadata(outpath)
&& meta.file_type().is_symlink()
{
std::fs::remove_file(outpath)?;
}
let mut options = std::fs::OpenOptions::new();
options.create(true).write(true).truncate(true); // <--- Truncate enabled!
#[cfg(unix)]
if let Some(mode) = unix_mode {
use std::os::unix::fs::OpenOptionsExt;
options.mode(mode);
}
#[cfg(windows)]
{
use std::os::windows::fs::OpenOptionsExt;
options.custom_flags(
windows_sys::Win32::Storage::FileSystem::FILE_FLAG_OPEN_REPARSE_POINT
| windows_sys::Win32::Storage::FileSystem::FILE_FLAG_SEQUENTIAL_SCAN,
);
}
let file = options.open(outpath)?;Key observations in this execution flow:
st_nlink > 1):
symlink_metadata reports is_symlink() == false for hard links. If a destination path already exists as a hard link pointing to an external file, create_outfile does not unlink it. It opens the path with options.create(true).write(true).truncate(true). Consequently, the external file sharing the same inode is truncated to 0 bytes and overwritten by copy_into.O_NOFOLLOW on Unix:
While Windows sets FILE_FLAG_OPEN_REPARSE_POINT, Unix targets do not configure OpenOptionsExt::custom_flags(libc::O_NOFOLLOW). If a path resolves to a link when open is invoked, the kernel follows the link and applies O_TRUNC immediately.// src/read/extract.rs:326-333
if file.metadata()?.file_type().is_symlink()
|| std::fs::symlink_metadata(outpath).is_ok_and(|meta| meta.file_type().is_symlink())
{
return Err(std::io::Error::new(
std::io::ErrorKind::PermissionDenied,
"Extracted file cannot be written through a symbolic link",
));
}The check file.metadata()?.file_type().is_symlink() calls fstat on the descriptor. On Unix, this queries the underlying target rather than the link, returning false for regular files.
echo "ORIGINAL_CONFIG_VALUE" > /tmp/target_file.confmkdir -p /tmp/dest
ln /tmp/target_file.conf /tmp/dest/app.confapp.conf with new content:echo "OVERWRITTEN_CONTENT" > payload.txt
zip -j archive.zip payload.txt
# Rename entry inside zip to app.conf/tmp/dest using ZipArchive::extract:archive.extract("/tmp/dest")?;cat /tmp/target_file.confObserved Result:
/tmp/target_file.conf now contains OVERWRITTEN_CONTENT. Because create_outfile does not inspect hard link counts or unlink existing regular files, the external inode was truncated and overwritten during extraction.
Arbitrary File Overwrite and File Destruction (CWE-59: Improper Link Resolution Before File Access, CWE-367: Time-of-check Time-of-use Race Condition).
Applications, backend services, or CI/CD pipelines extracting ZIP archives on Unix/Linux systems into shared directories (e.g. /tmp, shared volume mounts) or directories containing pre-existing hard links can have arbitrary external files truncated and overwritten.
If targeted at executable scripts, configuration files, or user profile environments, this can lead to privilege escalation or service disruption with the permissions of the extracting process.
Source: NVD
Free Vulnerability Assessment
Evaluate your cloud security practices across 9 security domains to benchmark your risk level and identify gaps in your defenses.
Get a personalized demo
"Best User Experience I have ever seen, provides full visibility to cloud workloads."
"Wiz provides a single pane of glass to see what is going on in our cloud environments."
"We know that if Wiz identifies something as critical, it actually is."