php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70417 PharData::compress() doesn't close temp file
Submitted: 2015-09-03 10:34 UTC Modified: 2017-01-05 17:53 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: r-orlowski at o2 dot pl Assigned: cmb
Status: Closed Package: *Compression related
PHP Version: 5.6.12 OS: Ubuntu 14.04 LTS
Private report: No CVE-ID:
 [2015-09-03 10:34 UTC] r-orlowski at o2 dot pl
Description:
------------
I need to archive a lot (>1000 && <2000) of files into plenty small archives (~900) via PHP application. I used PharData class to create archives. During script run I recieved "failed to open dir: Too many open files" error. After debug my whole application I found that calling PharData::compress() open some /tmp file that is never closed. Calling compress() in a loop lead to rising count of open files. 


Test script:
---------------
<?php

function archiveDir($archiveName, $dir)
{
    system("lsof -p ".getmypid()." | wc -l");  // on my local host give 72
    $arch = new \PharData($archiveName);
    $arch->buildFromDirectory($dir);
    system("lsof -p ".getmypid()." | wc -l"); // on my local host give 73 - buildFromDirectory open $dir
    system("lsof -p ".getmypid()." | grep /tmp/"); // empty result - no /tmp/ files open
    $arch->compress(\Phar::GZ);
    system("lsof -p ".getmypid()." | wc -l"); // on my local host give 74 - compress open /tmp/phppI7yJX file
}

archiveDir("./testArchive.tar", "./");
system("lsof -p ".getmypid()." | wc -l"); // on my local host give 73 - $dir opened by DirectoryIterator (line 7) is closed
system("lsof -p ".getmypid()." | grep /tmp/"); // we have still opened  /tmp/phppI7yJX file

Expected result:
----------------
Last lsof call should return same count of open files as first call of lsof.

Actual result:
--------------
lsof called after archiveDir() show, that we have one more open file than before archiveDir() call

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-09-03 12:11 UTC] cmb@php.net
-Status: Open +Status: Analyzed -Assigned To: +Assigned To: cmb
 [2015-09-03 12:11 UTC] cmb@php.net
Indeed, when Phar::compress() is called a temporary file is
opened[1], but not closed[2] on success.

[1] <https://github.com/php/php-src/blob/php-5.6.12/ext/phar/phar_object.c#L2255>
[2] <https://github.com/php/php-src/blob/php-5.6.12/ext/phar/phar_object.c#L2342>
 [2015-09-03 12:27 UTC] cmb@php.net
-Summary: \PharData::compress lead to "too many open files" +Summary: PharData::compress() doesn't close temp file
 [2015-09-03 14:24 UTC] cmb@php.net
Correction: closing of the temp file should only happen when
the Phar object is destroyed[1], but not earlier.

[1] <https://github.com/php/php-src/blob/php-5.6.12/ext/phar/phar.c#L288-L295>
 [2015-09-03 15:43 UTC] cmb@php.net
-Assigned To: cmb +Assigned To:
 [2015-09-03 15:43 UTC] cmb@php.net
I've submitted PR #1500.
 [2015-11-04 02:37 UTC] kalaychit55 at love dot com
kalaychit55@love.com
 [2015-12-13 04:44 UTC] kalaychit55 at love dot com
subscribe
 [2017-01-05 17:52 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=995ecffbb2ef972c2d01200ee15b39feb7c6d066
Log: Fix #70417: PharData::compress() doesn't close temp file
 [2017-01-05 17:52 UTC] cmb@php.net
-Status: Analyzed +Status: Closed
 [2017-01-05 17:53 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Fri Apr 28 23:01:35 2017 UTC