提取用户上传的档案而不暴露于 ZipBombs?

发布于 2024-10-05 00:28:18 字数 66 浏览 0 评论 0原文

我的问题很简单:如何确保(或阻止)用户上传解压后填满整个磁盘空间的存档(所谓的 ZipBomb)?我正在使用 PHP。

My question is simple: how do I make sure (or prevent) a user from uploading an archive that upon extraction fills the entire disc space (a so-called ZipBomb)? I am using PHP.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回忆躺在深渊里 2024-10-12 00:28:18

在提取存档之前,请使用 PHP Zip 库函数来确保提取后内容在总大小限制内。

例如:

$zip = zip_open('uploaded.zip');
$file = zip_read($zip);
$totalsize = 0;

while ($file) {
    $totalsize += zip_entry_filesize($file);
    $file = zip_read($zip); // read next file
}

zip_close($zip);

if ($totalsize > SIZE_LIMIT) {
    // not allowed!
}

Before extracting your archive, use the PHP Zip library functions to ensure that, when extracted, the contents fall within a total size limit.

For example:

$zip = zip_open('uploaded.zip');
$file = zip_read($zip);
$totalsize = 0;

while ($file) {
    $totalsize += zip_entry_filesize($file);
    $file = zip_read($zip); // read next file
}

zip_close($zip);

if ($totalsize > SIZE_LIMIT) {
    // not allowed!
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文