php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44501 file_put_contents writes empty file with zlib and LOCK_EX
Submitted: 2008-03-22 03:06 UTC Modified: 2011-11-16 12:33 UTC
Votes:3
Avg. Score:3.7 ± 1.2
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: david at acz dot org Assigned: iliaa (profile)
Status: Closed Package: Streams related
PHP Version: 5.2.5 OS: SLES 10 x86_64
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
2 + 50 = ?
Subscribe to this entry?

 
 [2008-03-22 03:06 UTC] david at acz dot org
Description:
------------
When passing LOCK_EX to file_put_contents() using a "compress.zlib" stream, the function creates a valid gzip file (non-empty) containing zero un-compressed bytes (gunzip outputs nothing) and returns false.

This was reported in #42468, but wasn't actually fixed.  The function needs to fail BEFORE it opens (and destroys) the output file.


Reproduce code:
---------------
<?
    $name = "/tmp/hello.txt.gz";
    $file = "compress.zlib://" . $name;

    var_dump(file_put_contents($file, "hello", LOCK_EX));
    var_dump(filesize($name));
    var_dump(file_get_contents($file));
?>


Expected result:
----------------
int(5)
int(31)
string(5) "hello"


Actual result:
--------------
bool(false)
int(26)
string(0) ""

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-03-25 13:33 UTC] jani@php.net
Ilia, the fix propably wasn't quite right, and I get this with the example script:

[jani@localhost ~]$ /home/jani/src/build/php_5_2/sapi/cli/php  t.php

Warning: file_put_contents(compress.zlib:///tmp/hello.txt.gz): failed to open stream: Inappropriate ioctl for device in /home/jani/t.php on line 5
bool(false)
int(0)
string(0) ""
                    
/home/jani/src/php-5.2/main/streams/streams.c(390) : Stream of type 'STDIO' 0x9504c4c (path:/tmp/hello.txt.gz) was not closed
[Tue Mar 25 15:30:11 2008]  Script:  't.php'
/home/jani/src/php-5.2/main/streams/streams.c(227) :  Freeing 0x09504C4C (128 bytes), script=t.php
/home/jani/src/php-5.2/ext/zlib/zlib_fopen_wrapper.c(127) : Actual location (location was relayed)
=== Total 1 memory leaks detected ===

 [2008-05-06 14:04 UTC] andron at kpi dot ua
Hello!
I have the same problem
/var/tmp/portage/dev-lang/php-5.2.6/work/php-5.2.6/main/streams/streams.c(390) : Stream of type 'STDIO' 0x8386378 (path:./storage/706e362fa415aa530247b0c4a372b249) was not closed

What infomation you need too?
 [2008-09-16 00:27 UTC] iliaa@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows (zip):
 
  http://snaps.php.net/win32/php5.3-win32-latest.zip

For Windows (installer):

  http://snaps.php.net/win32/php5.3-win32-installer-latest.msi

Seems to work fine in 5.3 CVS
 [2008-09-23 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2011-11-16 12:33 UTC] felipe@php.net
-Status: No Feedback +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jul 15 18:01:29 2024 UTC