Bug #49148 [Com]: combination of stream_get_line and fseek does not work correctly

From: Date: Thu, 14 Oct 2010 23:22:45 +0000
Subject: Bug #49148 [Com]: combination of stream_get_line and fseek does not work correctly
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-155190@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=49148&edit=1

 ID:                 49148
 Comment by:         arl at andrewrlevine dot com
 Reported by:        mugeso at mugeso dot com
 Summary:            combination of stream_get_line and fseek does not
                     work correctly
 Status:             Open
 Type:               Bug
 Package:            Streams related
 Operating System:   win32 only - Windows XP SP3
 PHP Version:        5.2.10
 Block user comment: N

 New Comment:

I can confirm this bug (on Ubuntu using PHP 5.2.10-2ubuntu6.5 with
Suhosin-Patch 
0.9.7 (cli) (built: May 21 2010 06:30:21) )

Here is a workaround function I made that seems to work:

function stream_get_line_fixed($handle, $length, $ending) {
    // Only allow 3 tries since if there's a genuine failure we don't
want to 
loop forever
    $tries = 3;
    $ret = FALSE;
    while ($ret === FALSE && $tries--) {
      $ret = stream_get_line($handle, $length, $ending);
    }
    return $ret;
  }


Previous Comments:
------------------------------------------------------------------------
[2009-08-31 20:04:38] garretts@php.net

This is reproduceable on Linux too.




------------------------------------------------------------------------
[2009-08-04 07:44:16] mugeso at mugeso dot com

Description:
------------
When use in combination of stream_get_line and fseek,
reading a file which has only 2 lines without ending on EOF(like below)
does fail.
This happens on only Windows and with only "2lines file without ending
on EOF".



Reproduce code:
---------------
2lines.txt
--
a<CRLF>
b<EOF>

phpfile:
--
<?php
$file = dirname(__FILE__) . '/2lines.txt';
$fp = fopen($file, "rb");
var_dump(stream_get_line($fp, null, "\xd\xa"));
fseek($fp, ftell($fp)); // expected that this does not affect result.
var_dump(stream_get_line($fp, null, "\xd\xa"));

Expected result:
----------------
string(1) "a"
string(1) "b"


Actual result:
--------------
string(1) "a"
bool(false)



------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=49148&edit=1


Thread (4 messages)

« previous php.bugs (#155190) next »