Skip to content

Fix #77978: Dirname ending in colon unzips to wrong dir #7528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/zip/php_zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ static char * php_zip_make_relative_path(char *path, size_t path_len) /* {{{ */
return path;
}

if (i >= 2 && (path[i -1] == '.' || path[i -1] == ':')) {
/* i is the position of . or :, add 1 for / */
if (i >= 2 && path[i -1] == '.') {
/* i is the position of ., add 1 for / */
path_begin = path + i + 1;
break;
}
Expand Down
37 changes: 37 additions & 0 deletions ext/zip/tests/bug77978.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
--TEST--
Bug #77978 (Dirname ending in colon unzips to wrong dir)
--SKIPIF--
<?php
if (!extension_loaded("zip")) die("skip zip extension not available");
?>
--FILE--
<?php
$file = __DIR__ . "/bug77978.zip";
$target = __DIR__ . "/bug77978";

mkdir($target);

$zip = new ZipArchive();
$zip->open($file, ZipArchive::CREATE|ZipArchive::OVERWRITE);
$zip->addFromString("dir/test:/filename.txt", "contents");
$zip->close();

$zip->open($file);
// Windows won't extract filenames with colons; we suppress the warning
@$zip->extractTo($target, "dir/test:/filename.txt");
$zip->close();

var_dump(!file_exists("$target/filename.txt"));
var_dump(PHP_OS_FAMILY === "Windows" || file_exists("$target/dir/test:/filename.txt"));
?>
--EXPECT--
bool(true)
bool(true)
--CLEAN--
<?php
@unlink(__DIR__ . "/bug77978.zip");
@unlink(__DIR__ . "/bug77978/dir/test:/filename.txt");
@rmdir(__DIR__ . "/bug77978/dir/test:");
@rmdir(__DIR__ . "/bug77978/dir");
@rmdir(__DIR__ . "/bug77978");
?>