Skip to content

Commit d172596

Browse files
committed
Bug #69477 ext/zip: Fix handling of file names with colon sign
If the colon sign is used in a drive relative path (such as C:temp/file.txt), only the part following the colon should be used as the filename.
1 parent 585e638 commit d172596

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

ext/zip/php_zip.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,26 +102,31 @@ static char * php_zip_make_relative_path(char *path, size_t path_len) /* {{{ */
102102
return NULL;
103103
}
104104

105-
if (path_len == 1 && (path[0] == '.' || IS_SLASH(path[0]))) {
105+
if (path_len == 1 && (path[0] == '.' || IS_SLASH(path[0]) || path[0] == ':')) {
106106
return NULL;
107107
}
108108

109109
i = path_len;
110110

111111
while (1) {
112-
while (i > 0 && !IS_SLASH(path[i])) {
112+
while (i > 0 && !(IS_SLASH(path[i]) || path[i] == ':')) {
113113
i--;
114114
}
115115

116116
if (!i) {
117-
if (IS_SLASH(path[0])) {
117+
if (IS_SLASH(path[0]) || path[0] == ':') {
118118
path_begin = path + 1;
119119
} else {
120120
path_begin = path;
121121
}
122122
break;
123123
}
124124

125+
if (i == 1 && path[i] == ':') {
126+
path_begin = path + i + 1;
127+
break;
128+
}
129+
125130
if (i >= 1 && path[i - 1] == ':') {
126131
path_begin = path + i + 1;
127132
break;

ext/zip/tests/bug69477.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ if (PHP_OS_FAMILY === 'Windows') {
3535
'C:/a./b./file12.txt' => 'a_/b_/file12.txt',
3636
'a/b:/c/file13.txt' => 'c/file13.txt',
3737
'a/b/c/file14.' => 'a/b/c/file14_',
38+
'C:a./b./file15.txt' => 'a_/b_/file15.txt',
3839
];
3940
} else {
4041
$paths = [
@@ -52,6 +53,7 @@ if (PHP_OS_FAMILY === 'Windows') {
5253
'C:/a./b./file12.txt' => 'a./b./file12.txt',
5354
'a/b:/c/file13.txt' => 'c/file13.txt',
5455
'a/b/c/file14.' => 'a/b/c/file14.',
56+
'C:a./b./file15.txt' => 'a./b./file15.txt',
5557
];
5658
}
5759

0 commit comments

Comments
 (0)