Skip to content

php ZipArchive file path bug #13211

@annopnod

Description

@annopnod

Description

The following code:

php code
$zip = new ZipArchive();
$zip->open("c:/test.zip");
$zip->statName("a/b/c.txt");
$zip->statName("a//b//c.txt");
$zip->statName("/a/b/c.txt");
$zip->statName("//a/b/c.txt");
$zip->statName("\a\b\c.txt");

should output
array => name,crc,size

but output
$zip->statName("a/b/c.txt"); output false
$zip->statName("a//b//c.txt"); output false
$zip->statName("/a/b/c.txt"); output false
$zip->statName("//a/b/c.txt"); output false
$zip->statName("\a\b\c.txt"); output array => name,crc,size

solve immediate problems add function
public function Normalize($path, $remove_slashes_frist = false) {
$output = array();
$explode = explode("/", str_replace(array('/', '\'), "/", ($path)));
foreach ($explode as $value) {
if ($value == "..") {
array_pop($output);
} else if ($value !== ".") {
$output[] = ($value);
}
}
$strout = implode("/", $output);
while (strpos($strout, "//") !== false) {
$strout = str_replace("//", "/", $strout);
}
if ($remove_slashes_frist) {
$strout = ltrim($strout, "/");
}
return $strout;
}

PHP Version

php 7-8

Operating System

window 11

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions