#44607 [Opn]: stream_get_line return incorrect values

[email protected] ("amoo_miki at yahoo dot com")
Newsgroups php.bugs
Message-ID <[email protected]>
 ID:               44607
 User updated by:  amoo_miki at yahoo dot com
 Reported By:      amoo_miki at yahoo dot com
 Status:           Open
 Bug Type:         Streams related
 Operating System: *
-PHP Version:      5.2CVS-2008-07-14
+PHP Version:      5.x upto 5.3-alpha2
 New Comment:

The bug still persists.


Previous Comments:
------------------------------------------------------------------------

[2008-07-14 21:54:02] amoo_miki at yahoo dot com

I should also add that the workaround (that works for this example
file) does not always work.

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

[2008-07-14 21:45:58] amoo_miki at yahoo dot com

Also tried with the latest CVS snapshot of 5.2.7-dev and it still gives
incorrect results.

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

[2008-07-14 21:30:22] amoo_miki at yahoo dot com

Tested this with PHP v5.2.6 on Windows 2008 Server and FreeBSD 7.0 and
it still returns incorrect results.

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

[2008-04-02 12:14:33] amoo_miki at yahoo dot com

Using:

PHP 5.2.6RC4-dev (cli) (built: Apr  2 2008 08:04:44)

Still i get the faulty output:

Found in source at 9295

Location in stream: 15000
Rewinding...
Location in stream: 15000

Attempting fix...
Location in stream: 9307
Rewinding...
Location in stream: 9307

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

[2008-04-02 11:56:25] amoo_miki at yahoo dot com

Description:
------------
On some occasions stream_get_line acts weired by attempting the first
seek without considering the "end of line" string.

Below is the sample code that shows the problem with a workaround to
temporarily solve the issue (that might ring some bells for the person
who plans on fixing this).

The code uses a small binary JPX file that can be fetched from
http://barahmand.com/streambug/sample.txt

Reproduce code:
---------------
<?php 
$filename = 'sample.txt';
$arr = explode('<EndOfFrame>', file_get_contents($filename));
echo "Found in source at ".strlen($arr[0])."\n\n";
$fp = fopen($filename, "rb");
stream_get_line($fp, 15000, "<EndOfFrame>");
echo "Location in stream: ".ftell($fp)."\n";
echo "Rewinding...\n"; rewind($fp);
stream_get_line($fp, 15000, "<EndOfFrame>");
echo "Location in stream: ".ftell($fp)."\n";
rewind($fp);
echo "\nAttempting fix...\n";
stream_get_line($fp, 1, "<EndOfFrame>");
stream_get_line($fp, 15000, "<EndOfFrame>");
echo "Location in stream: ".ftell($fp)."\n";
echo "Rewinding...\n"; rewind($fp);
stream_get_line($fp, 15000, "<EndOfFrame>");
echo "Location in stream: ".ftell($fp)."\n";
fclose($fp);
?>

Expected result:
----------------
Found in source at 9295

Location in stream: 9307
Rewinding...
Location in stream: 9307

Attempting fix...
Location in stream: 9307
Rewinding...
Location in stream: 9307

Actual result:
--------------
Found in source at 9295

Location in stream: 15000
Rewinding...
Location in stream: 15000

Attempting fix...
Location in stream: 9307
Rewinding...
Location in stream: 9307


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


-- 
Edit this bug report at http://bugs.php.net/?id=44607&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.