Req #39598 [Opn->Csd]: error verification after fwrite()
| From: | nikic@php.net | Date: | Thu, 25 Jul 2019 09:10:26 +0000 |
| Subject: | Req #39598 [Opn->Csd]: error verification after fwrite() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-221936@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=39598&edit=1
ID: 39598
Updated by: nikic@php.net
Reported by: max at nucleus dot it
Summary: error verification after fwrite()
-Status: Open
+Status: Closed
Type: Feature/Change Request
-Package: Feature/Change Request
+Package: *General Issues
Operating System: Linux
PHP Version: 5.2.0
-Assigned To:
+Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
In PHP 7.4 fwrite() will return 0 for EAGAIN/EWOULDBLOCK and false for other errors, in line with
the requested behavior.
Previous Comments:
------------------------------------------------------------------------
[2018-06-30 20:24:33] novelesco at centrum dot cz
Please, at least fix the documentation.
------------------------------------------------------------------------
[2016-01-22 14:04:55] salsi at icosaedro dot it
Missing error detection in streams and filters is a general flaw in the internal i/o handling
affecting all the related functions (fopen, fread, fwrite, fflush, fclose) which is really severe,
because it affects the safety of any file and data transfer, and would deserve maximum attention and
urgency for being fix asap. I may list several other reports that demonstrates missing detection of
corrupted file system missing detection of invalid encoded data and so on:
fread() does not detect file access error
https://bugs.php.net/bug.php?id=71384
(Also includes disk image containing a damaged file for testing.)
require* and include* do not detect input/output error
https://bugs.php.net/bug.php?id=71385
(Probably related to the bug above.)
fread() does not detect decoding errors from filter zlib.inflate
https://bugs.php.net/bug.php?id=71417
(Probably missing propagation of errors through streams.)
fread() does not detects decoding errors from filter bzip2.decompress
https://bugs.php.net/bug.php?id=71263
(Probably the same as above.)
All these share the same common denominator: missing error propagation from libc to PHP user's
space.
------------------------------------------------------------------------
[2013-03-01 00:04:00] gauthierm@php.net
Here's a simple reproduce test case:
http://labs.silverorange.com/files/php-bug39598/php-bug-39598-test.phps
In this case, and EPIPE occurs. The fwrite call writes 0 bytes. No error code is
available and no PHP error is raised.
------------------------------------------------------------------------
[2006-11-22 22:53:31] max at nucleus dot it
Description:
------------
The documentation states tha fwrite() returns false in
case of error, but it doesn't do so if the actual write
fails.
For example if I asynchronously write to a pipe (such as
those obtained by proc_open()) I and the pipe is not ready
or is broken, fwrite() returns 0.
This could be a correct behaviour it I had a way to
determine the error.
The problem is that EAGAIN or EPIPE are completely
impossible to determine and I can't know if I need to wait
or I have to close the stream.
A possible solution would be to implement ferror() or
errno.
Reproduce code:
---------------
$Proc = proc_open($Cmd, $Streams, $Pipes, $CWD, $Env);
stream_set_blocking($Pipes[0], 0);
$Result = fwrite($Pipes[0], "test");
// If $Pipes[0] is not ready to receive data
// $Result is 0, but I can't know why.
// The real code I'm writing involves
// stream_select() and repeated reads and writes
// on multiple pipes.
Expected result:
----------------
fwrite() should return 0 when the stream is asynchrounous,
the C write() returns 0 and errno is EAGAIN.
fwrite() should return false in all other cases where the
C write() returns 0.
Alternatively a way to access ferror() or errno is needed.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=39598&edit=1