[php-src] Issue #13211: php ZipArchive file path bug
| From: | annopnod | Date: | Sun, 21 Jan 2024 13:14:03 +0000 |
| Subject: | [php-src] Issue #13211: php ZipArchive file path bug | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-246305@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/13211
Author: annopnod
### Description
The following code:
<?php
$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