Created
February 16, 2020 06:18
-
-
Save smalyshev/8e023915d57a986de3593a93b62f169a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 9c4b2b282129f9f3b5aeea7a45bfeb5bdf8e321e | |
Author: Stanislav Malyshev <stas@php.net> | |
Date: Sat Feb 15 22:17:14 2020 -0800 | |
Fix bug #79082 - Files added to tar with Phar::buildFromIterator have all-access permissions | |
diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c | |
index 2669413fe6..2987b64012 100644 | |
--- a/ext/phar/phar_object.c | |
+++ b/ext/phar/phar_object.c | |
@@ -1439,6 +1439,7 @@ static int phar_build(zend_object_iterator *iter, void *puser) /* {{{ */ | |
char *str_key; | |
zend_class_entry *ce = p_obj->c; | |
phar_archive_object *phar_obj = p_obj->p; | |
+ php_stream_statbuf ssb; | |
value = iter->funcs->get_current_data(iter); | |
@@ -1718,6 +1719,16 @@ after_open_fp: | |
php_stream_copy_to_stream_ex(fp, p_obj->fp, PHP_STREAM_COPY_ALL, &contents_len); | |
data->internal_file->uncompressed_filesize = data->internal_file->compressed_filesize = | |
php_stream_tell(p_obj->fp) - data->internal_file->offset; | |
+ if (php_stream_stat(fp, &ssb) != -1) { | |
+ data->internal_file->flags = ssb.sb.st_mode & PHAR_ENT_PERM_MASK ; | |
+ } else { | |
+#ifndef _WIN32 | |
+ mode_t mask; | |
+ mask = umask(0); | |
+ umask(mask); | |
+ data->internal_file->flags &= ~mask; | |
+#endif | |
+ } | |
} | |
if (close_fp) { | |
diff --git a/ext/phar/tests/bug79082.phpt b/ext/phar/tests/bug79082.phpt | |
new file mode 100644 | |
index 0000000000..5b46105a60 | |
--- /dev/null | |
+++ b/ext/phar/tests/bug79082.phpt | |
@@ -0,0 +1,50 @@ | |
+--TEST-- | |
+Phar: Bug #79082: Files added to tar with Phar::buildFromIterator have all-access permissions | |
+--SKIPIF-- | |
+<?php | |
+if (!extension_loaded("phar")) die("skip"); | |
+if (defined("PHP_WINDOWS_VERSION_MAJOR")) die("skip not for Windows") | |
+?> | |
+--FILE-- | |
+<?php | |
+umask(022); | |
+var_dump(decoct(umask())); | |
+ | |
+foreach([Phar::TAR => 'tar', Phar::ZIP => 'zip'] as $mode => $ext) { | |
+ clearstatcache(); | |
+ $phar = new PharData(__DIR__ . '/test79082.' . $ext, null, null, $mode); | |
+ $phar->buildFromIterator(new \RecursiveDirectoryIterator(__DIR__ . '/test79082', \FilesystemIterator::SKIP_DOTS), __DIR__ . '/test79082'); | |
+ $phar->extractTo(__DIR__); | |
+ var_dump(decoct(stat(__DIR__ . '/test79082-testfile')['mode'])); | |
+ var_dump(decoct(stat(__DIR__ . '/test79082-testfile2')['mode'])); | |
+ unlink(__DIR__ . '/test79082-testfile'); | |
+ unlink(__DIR__ . '/test79082-testfile2'); | |
+} | |
+foreach([Phar::TAR => 'tar', Phar::ZIP => 'zip'] as $mode => $ext) { | |
+ clearstatcache(); | |
+ $phar = new PharData(__DIR__ . '/test79082-d.' . $ext, null, null, $mode); | |
+ $phar->buildFromDirectory(__DIR__ . '/test79082'); | |
+ $phar->extractTo(__DIR__); | |
+ var_dump(decoct(stat(__DIR__ . '/test79082-testfile')['mode'])); | |
+ var_dump(decoct(stat(__DIR__ . '/test79082-testfile2')['mode'])); | |
+ unlink(__DIR__ . '/test79082-testfile'); | |
+ unlink(__DIR__ . '/test79082-testfile2'); | |
+} | |
+?> | |
+--CLEAN-- | |
+<? | |
+unlink(__DIR__ . '/test79082.tar'); | |
+unlink(__DIR__ . '/test79082.zip'); | |
+unlink(__DIR__ . '/test79082-d.tar'); | |
+unlink(__DIR__ . '/test79082-d.zip'); | |
+?> | |
+--EXPECT-- | |
+string(2) "22" | |
+string(6) "100644" | |
+string(6) "100400" | |
+string(6) "100644" | |
+string(6) "100400" | |
+string(6) "100644" | |
+string(6) "100400" | |
+string(6) "100644" | |
+string(6) "100400" | |
diff --git a/ext/phar/tests/test79082/test79082-testfile b/ext/phar/tests/test79082/test79082-testfile | |
new file mode 100644 | |
index 0000000000..9daeafb986 | |
--- /dev/null | |
+++ b/ext/phar/tests/test79082/test79082-testfile | |
@@ -0,0 +1 @@ | |
+test | |
diff --git a/ext/phar/tests/test79082/test79082-testfile2 b/ext/phar/tests/test79082/test79082-testfile2 | |
new file mode 100644 | |
index 0000000000..9daeafb986 | |
--- /dev/null | |
+++ b/ext/phar/tests/test79082/test79082-testfile2 | |
@@ -0,0 +1 @@ | |
+test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment