php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48870 File is missing 2048 bytes after fclose. When script ends the file is complete
Submitted: 2009-07-09 15:15 UTC Modified: 2009-07-09 18:43 UTC
From: lorenz dot werner at michel-consulting dot de Assigned:
Status: Closed Package: Unknown/Other Function
PHP Version: 5.2.10 OS: gentoo
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: lorenz dot werner at michel-consulting dot de
New email:
PHP Version: OS:

 

 [2009-07-09 15:15 UTC] lorenz dot werner at michel-consulting dot de
Description:
------------
Since I upgraded to PHP 5.2.10 I have got an problem with files not beiing completly written. Exactly 2048 bytes are missing while the script is running. Even after fclose it is not completley written.

If I open the file for reading again and then close it again the file is complete. But that can't be correct... or is it?

Reproduce code:
---------------
$fh = fopen($pdf_tarfile, "wb");
$ch = curl_init(PDF_SERVICE_URL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_FILE, $fh);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_exec($ch);
$return_code = curl_errno($ch);
if( $return_code ) {
	trigger_error('curl returned error ' . $return_code . ': ' . curl_error($ch), E_USER_ERROR);
	return false;
}
curl_close($ch);
fclose($fh);

// It only works with this workaround
{
	$fh = fopen($pdf_tarfile, "rb");
	fclose($fh);
}

$cmd = 'tar'
. ' -x' // extract
. ' -f ' . escapeshellarg($pdf_tarfile) // this file
. ' -C ' . escapeshellarg($path); // into this directory

$stdout = array();
exec($cmd . ' 2>&1', $stdout, $return_code);
if ($return_code) {
	trigger_error('tar returned error ' . $return_code . ': ' . implode("\n", $stdout), E_USER_ERROR);
	return false;
}


Expected result:
----------------
Correctly unpacked tar archive.

Actual result:
--------------
Tar fails to unpack the file because it is missing the last 2048 Bytes.

If I run the command manually after the script is finished, the file can be unpacked without any problem at all.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-09 16:42 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2009-07-09 18:43 UTC] lorenz dot werner at michel-consulting dot de
Thank you for your fast and competent feedback.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 10:01:33 2025 UTC