summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStanislav Malyshev <stas@php.net>2018-12-02 21:06:13 +0100
committerChristoph M. Becker <cmbecker69@gmx.de>2018-12-03 14:46:39 +0100
commit0f658b38e854191d98a6715b278c0c9c8a7a0e68 (patch)
tree7eee341e82cbe32ccb2d35ab74351b3b74a6c0b0
parentea302f8b085466da1f417070f966ccce1e5ea9d2 (diff)
downloadphp-git-0f658b38e854191d98a6715b278c0c9c8a7a0e68.tar.gz
Fix bug #77022 - use file mode or umask for new files
(cherry picked from commit 69f5e7992bfc239e42a3a82e290399ca75bc56a6) (cherry picked from commit 2fba1e2f59c85c038e60a95c2c651d0ae3e8f1cf)
-rw-r--r--ext/phar/phar_object.c15
-rw-r--r--ext/phar/tests/bug77022.phpt36
-rw-r--r--ext/phar/tests/stat.phpt1
3 files changed, 50 insertions, 2 deletions
diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c
index 602cc7a7a7..e4aad18092 100644
--- a/ext/phar/phar_object.c
+++ b/ext/phar/phar_object.c
@@ -3614,7 +3614,8 @@ static void phar_add_file(phar_archive_data **pphar, char *filename, size_t file
char *error;
size_t contents_len;
phar_entry_data *data;
- php_stream *contents_file;
+ php_stream *contents_file = NULL;
+ php_stream_statbuf ssb;
if (filename_len >= sizeof(".phar")-1) {
start_pos = ('/' == filename[0] ? 1 : 0); /* account for any leading slash: multiple-leads handled elsewhere */
@@ -3651,10 +3652,20 @@ static void phar_add_file(phar_archive_data **pphar, char *filename, size_t file
}
php_stream_copy_to_stream_ex(contents_file, data->fp, PHP_STREAM_COPY_ALL, &contents_len);
}
-
data->internal_file->compressed_filesize = data->internal_file->uncompressed_filesize = contents_len;
}
+ if (contents_file != NULL && php_stream_stat(contents_file, &ssb TSRMLS_CC) != -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
+ }
+
/* check for copy-on-write */
if (pphar[0] != data->phar) {
*pphar = data->phar;
diff --git a/ext/phar/tests/bug77022.phpt b/ext/phar/tests/bug77022.phpt
new file mode 100644
index 0000000000..c78d1bdafd
--- /dev/null
+++ b/ext/phar/tests/bug77022.phpt
@@ -0,0 +1,36 @@
+--TEST--
+Phar: Bug #77022: PharData always creates new files with mode 0666
+--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()));
+
+$sFile = tempnam(__DIR__, 'test77022');
+var_dump(decoct(stat($sFile)['mode']));
+
+foreach([Phar::TAR => 'tar', Phar::ZIP => 'zip'] as $mode => $ext) {
+ clearstatcache();
+ $phar = new PharData(__DIR__ . '/test77022.' . $ext, null, null, $mode);
+ $phar->addFile($sFile, 'test-file-phar');
+ $phar->addFromString("test-from-string", 'test-file-phar');
+ $phar->extractTo(__DIR__);
+ var_dump(decoct(stat(__DIR__ . '/test-file-phar')['mode']));
+ var_dump(decoct(stat(__DIR__ . '/test-from-string')['mode']));
+ unlink(__DIR__ . '/test-file-phar');
+ unlink(__DIR__ . '/test-from-string');
+ unlink(__DIR__ . '/test77022.' . $ext);
+}
+unlink($sFile);
+?>
+--EXPECT--
+string(2) "22"
+string(6) "100600"
+string(6) "100600"
+string(6) "100644"
+string(6) "100600"
+string(6) "100644" \ No newline at end of file
diff --git a/ext/phar/tests/stat.phpt b/ext/phar/tests/stat.phpt
index c397b3e4a0..f14d0da1a6 100644
--- a/ext/phar/tests/stat.phpt
+++ b/ext/phar/tests/stat.phpt
@@ -7,6 +7,7 @@ phar.require_hash=1
phar.readonly=0
--FILE--
<?php
+umask(0);
Phar::interceptFileFuncs();
var_dump(stat(""));