RE: [PHP-DEV] Fix for 49148 (combination of stream_get_line and fseek does not work correctly)
| From: | Garrett Serack | Date: | Tue, 08 Sep 2009 17:05:04 +0000 |
| Subject: | RE: [PHP-DEV] Fix for 49148 (combination of stream_get_line and fseek does not work correctly) | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-45522@lists.php.net to get a copy of this message | ||
Hmmm.
stream_get_line doesn't appear to work correctly with bz streams:
--example.php--
$tmpname = tempnam("/tmp", "tmp");
$tmp = fopen($tmpname, "w");
stream_filter_append($tmp, 'bzip2.compress', STREAM_FILTER_WRITE);
fwrite($tmp, "line1\n");
fwrite($tmp, "line2\n");
fwrite($tmp, "line3");
fclose($tmp);
// reopen for reading using stream_get_line
$tmp = fopen($tmpname, "r");
stream_filter_prepend($tmp, 'bzip2.decompress', STREAM_FILTER_READ);
var_dump(stream_get_line($tmp, null, "\n"));
var_dump(stream_get_line($tmp, null, "\n"));
var_dump(stream_get_line($tmp, null, "\n"));
var_dump(stream_get_line($tmp, null, "\n"));
fclose($tmp);
// reopen for reading again, this time using fgets()
$tmp = fopen($tmpname, "r");
stream_filter_prepend($tmp, 'bzip2.decompress', STREAM_FILTER_READ);
var_dump(fgets($tmp));
var_dump(fgets($tmp));
var_dump(fgets($tmp));
var_dump(fgets($tmp));
fclose($tmp);
--------------------
--output--
string(5) "line1"
string(0) ""
string(0) ""
string(0) ""
string(6) "line1
"
string(6) "line2
"
string(6) "line2
"
bool(false)
--------------------
Both pre- and post- patch, the stream_get_line doesn't work right with the bz stream. I get the
first read ok, then subsequent ones don't work.
fgets() works perfectly fine however.
Perhaps the whole thing is a tad buggier than it should be.
Any ideas?
G
-----Original Message-----
From: Pierre Joye [mailto:pierre.php@gmail.com]
Sent: Thursday, September 03, 2009 2:16 PM
To: Garrett Serack
Cc: Hans Åhlin; internals@lists.php.net
Subject: Re: [PHP-DEV] Fix for 49148 (combination of stream_get_line and fseek does not work
correctly)
hi Garrett,
As the patch looks simple I still like to have a bunch set of other
tests before applying it (especially for 5.2/3). The tests should
ideally use various stream backends (user, bz, etc.).
Cheers,
On Thu, Sep 3, 2009 at 10:38 PM, Garrett Serack<garretts@microsoft.com> wrote:
> Ah, no. That is correctly handled. (the default max line length is 8k), and passing in a larger
> number works just fine.
>
> G
> -----Original Message-----
> From: Garrett Serack
> Sent: Thursday, September 03, 2009 1:32 PM
> To: Garrett Serack; Hans Åhlin; internals@lists.php.net
> Subject: RE: [PHP-DEV] Fix for 49148 (combination of stream_get_line and fseek does not work
> correctly)
>
> Ah, I found another case... when the line length is longer than the read buffer. I'll post
> again in a few minutes.
>
> G
>
> -----Original Message-----
> From: Garrett Serack [mailto:garretts@microsoft.com]
> Sent: Thursday, September 03, 2009 1:22 PM
> To: Hans Åhlin; internals@lists.php.net
> Subject: RE: [PHP-DEV] Fix for 49148 (combination of stream_get_line and fseek does not work
> correctly)
>
> Without the patch, That is what will you see (windows or linux). (Which is wrong...)
>
> The patch corrects the case where the stream has been fseek'd to the last line in the
> file, when the last line doesn't end with a line terminator. (where you see 'false'
> in the results).
>
> Without the patch, the code mistakenly checks for EOF *after* characters have been read in,
> which is completely unnecessary (and incorrect) since the read operation has taken place already.
>
> There could be some question as to the proper behavior when the stream *is* at EOF, and
> stream_get_line is called (return NULL or empty string), but the behavior previously was to return
> the empty string (keep calling stream_get_line and once you reach the end, you will just get empty
> strings).
>
> G
>
> -----Original Message-----
> From: ahlin.hans@gmail.com [mailto:ahlin.hans@gmail.com] On Behalf Of Hans Åhlin
> Sent: Wednesday, September 02, 2009 10:29 PM
> To: internals@lists.php.net
> Subject: [PHP-DEV] Fix for 49148 (combination of stream_get_line and fseek does not work
> correctly)
>
> I just ran the test on Linux 2.6.29 FC11 Apache 2.2.13 and PHP 5.2.9
>
> Result:
>
> string 'line1' (length=5)
> string '' (length=0)
> string 'line1' (length=5)
> string '' (length=0)
> string 'line1' (length=5)
> string 'line2' (length=5)
> string 'line1' (length=5)
> boolean false
> string 'line1' (length=5)
> string 'line2' (length=5)
> string 'line1' (length=5)
> string 'line2' (length=5)
>
> --
> MvH / Hans Åhlin
> Tel: +46761488019
> http//www.kronan-net.com/
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
--
Pierre
http://blog.thepimp.net | http://www.libgd.org
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php