From 995ecffbb2ef972c2d01200ee15b39feb7c6d066 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Thu, 3 Sep 2015 16:37:29 +0200 Subject: [PATCH] Fix #70417: PharData::compress() doesn't close temp file According to the comment, it has not been deemed necessary to close compressed files. However, we don't want to keep unclosed file handles to save ressources. So we're also closing compressed archives, if they're not aliased. --- ext/phar/phar.c | 6 ++++-- ext/phar/tests/tar/bug70417.phpt | 36 ++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 ext/phar/tests/tar/bug70417.phpt diff --git a/ext/phar/phar.c b/ext/phar/phar.c index bf89220e0e..9d91fd26ae 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -284,11 +284,13 @@ int phar_archive_delref(phar_archive_data *phar) /* {{{ */ PHAR_G(last_phar) = NULL; PHAR_G(last_phar_name) = PHAR_G(last_alias) = NULL; - if (phar->fp && !(phar->flags & PHAR_FILE_COMPRESSION_MASK)) { + if (phar->fp && (!(phar->flags & PHAR_FILE_COMPRESSION_MASK) || !phar->alias)) { /* close open file handle - allows removal or rename of the file on windows, which has greedy locking only close if the archive was not already compressed. If it - was compressed, then the fp does not refer to the original file */ + was compressed, then the fp does not refer to the original file. + We're also closing compressed files to save resources, + but only if the archive isn't aliased. */ php_stream_close(phar->fp); phar->fp = NULL; } diff --git a/ext/phar/tests/tar/bug70417.phpt b/ext/phar/tests/tar/bug70417.phpt new file mode 100644 index 0000000000..0096b5a2a9 --- /dev/null +++ b/ext/phar/tests/tar/bug70417.phpt @@ -0,0 +1,36 @@ +--TEST-- +Bug #70417 (PharData::compress() doesn't close temp file) +--SKIPIF-- + +--FILE-- +addFromString('foo', 'bar'); +$arch->compress(Phar::GZ); +unset($arch); +$openFiles2 = countOpenFiles(); +var_dump($openFiles1 === $openFiles2); +?> +--CLEAN-- + +--EXPECT-- +bool(true) -- 2.50.1