php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49148 combination of stream_get_line and fseek does not work correctly
Submitted: 2009-08-04 07:44 UTC Modified: 2014-07-16 03:18 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: mugeso at mugeso dot com Assigned: yohgaki (profile)
Status: Closed Package: Streams related
PHP Version: 5.2.10 OS: win32 only - Windows XP SP3
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: mugeso at mugeso dot com
New email:
PHP Version: OS:

 

 [2009-08-04 07:44 UTC] 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)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-08-31 20:04 UTC] garretts@php.net
This is reproduceable on Linux too.



 [2010-10-15 01:22 UTC] arl at andrewrlevine dot com
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;
  }
 [2014-07-16 03:18 UTC] yohgaki@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: yohgaki
 [2014-07-16 03:18 UTC] yohgaki@php.net
It seems fixed in 5.4 and later with linux. Closing.
If you have issue on Windows. Please re-open.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Mar 14 09:01:29 2025 UTC