summaryrefslogtreecommitdiff
path: root/ext/phar
diff options
context:
space:
mode:
authorStanislav Malyshev <stas@php.net>2018-12-01 21:47:44 -0800
committerStanislav Malyshev <stas@php.net>2018-12-01 21:47:44 -0800
commit8136d130b61bc4da6a04b41f5e1cfbaa2a402458 (patch)
tree2694bba76823e3501c30959d8c27f4473580395e /ext/phar
parent94ec262fca2e832ab2e1c4f03bc68cbda6aa42ae (diff)
parent1aec05defdb43d474a3a52bffa3f77646a04fcdc (diff)
downloadphp-git-8136d130b61bc4da6a04b41f5e1cfbaa2a402458.tar.gz
Merge branch 'PHP-7.1' into PHP-7.2
* PHP-7.1: Fix bug #77022 - use file mode or umask for new files
Diffstat (limited to 'ext/phar')
-rw-r--r--ext/phar/phar_object.c15
-rw-r--r--ext/phar/tests/bug77022.phpt32
-rw-r--r--ext/phar/tests/stat.phpt1
3 files changed, 46 insertions, 2 deletions
diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c
index 40639c7851..2536d27209 100644
--- a/ext/phar/phar_object.c
+++ b/ext/phar/phar_object.c
@@ -3684,7 +3684,8 @@ static void phar_add_file(phar_archive_data **pphar, char *filename, int filenam
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 >= (int)sizeof(".phar")-1) {
start_pos = ('/' == filename[0] ? 1 : 0); /* account for any leading slash: multiple-leads handled elsewhere */
@@ -3721,10 +3722,20 @@ static void phar_add_file(phar_archive_data **pphar, char *filename, int filenam
}
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..66bcf66dd4
--- /dev/null
+++ b/ext/phar/tests/bug77022.phpt
@@ -0,0 +1,32 @@
+--TEST--
+Phar: Bug #77022: PharData always creates new files with mode 0666
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--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) {
+ $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(""));