Bug #60671 [NEW]: fread does not fail when operating on a write only stream

From: Date: Fri, 06 Jan 2012 14:29:44 +0000
Subject: Bug #60671 [NEW]: fread does not fail when operating on a write only stream
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-166259@lists.php.net to get a copy of this message
From:             
Operating system: Ubuntu 11.04
PHP version:      5.3.8
Package:          Streams related
Bug Type:         Bug
Bug description:fread does not fail when operating on a write only stream

Description:
------------
fread does not throw or generate any error when attempting to read from a
write only file stream.

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

$tmp = tempnam(sys_get_temp_dir(), 'test_');

$stream = fopen($tmp, 'w');
$data = "";

while(!feof($stream)){
  if(false === ($data .= fread($stream, 8192))){
    break;
  };
}

?>

Expected result:
----------------
Either feof to return false indicating end of file
Or fread erroring or returning false as a result of attempting to read a
write-only stream.

Actual result:
--------------
An infinite loop will occur.
feof will never end (doesn't reach the end of the file because it's in
write mode)
fread will never error despite attempting to read from a write only stream.

-- 
Edit bug report at https://bugs.php.net/bug.php?id=60671&edit=1
-- 
Try a snapshot (PHP 5.4):            https://bugs.php.net/fix.php?id=60671&r=trysnapshot54
Try a snapshot (PHP 5.3):            https://bugs.php.net/fix.php?id=60671&r=trysnapshot53
Try a snapshot (trunk):              https://bugs.php.net/fix.php?id=60671&r=trysnapshottrunk
Fixed in SVN:                        https://bugs.php.net/fix.php?id=60671&r=fixed
Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=60671&r=needdocs
Fixed in release:                    https://bugs.php.net/fix.php?id=60671&r=alreadyfixed
Need backtrace:                      https://bugs.php.net/fix.php?id=60671&r=needtrace
Need Reproduce Script:               https://bugs.php.net/fix.php?id=60671&r=needscript
Try newer version:                   https://bugs.php.net/fix.php?id=60671&r=oldversion
Not developer issue:                 https://bugs.php.net/fix.php?id=60671&r=support
Expected behavior:                   https://bugs.php.net/fix.php?id=60671&r=notwrong
Not enough info:                     https://bugs.php.net/fix.php?id=60671&r=notenoughinfo
Submitted twice:                     https://bugs.php.net/fix.php?id=60671&r=submittedtwice
register_globals:                    https://bugs.php.net/fix.php?id=60671&r=globals
PHP 4 support discontinued:          https://bugs.php.net/fix.php?id=60671&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=60671&r=dst
IIS Stability:                       https://bugs.php.net/fix.php?id=60671&r=isapi
Install GNU Sed:                     https://bugs.php.net/fix.php?id=60671&r=gnused
Floating point limitations:          https://bugs.php.net/fix.php?id=60671&r=float
No Zend Extensions:                  https://bugs.php.net/fix.php?id=60671&r=nozend
MySQL Configuration Error:           https://bugs.php.net/fix.php?id=60671&r=mysqlcfg



Thread (10 messages)

« previous php.bugs (#166259) next »