Bug #63240 [PATCH]: stream_get_line return contains delimiter string
| From: | datibbaw@php.net | Date: | Tue, 09 Oct 2012 09:02:19 +0000 |
| Subject: | Bug #63240 [PATCH]: stream_get_line return contains delimiter string | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-173958@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=63240&edit=1
ID: 63240
Patch added by: datibbaw@php.net
Reported by: scope at planetavent dot de
Summary: stream_get_line return contains delimiter string
Status: Open
Type: Bug
Package: Streams related
Operating System: Windows Server 2008 / RHEL 6.2
PHP Version: 5.3.17
Block user comment: N
Private report: N
New Comment:
The following patch has been added/updated:
Patch Name: getrecord-delimiter-search-fix
Revision: 1349773338
URL: https://bugs.php.net/patch-display.php?bug=63240&patch=getrecord-delimiter-search-fix&revision=1349773338
Previous Comments:
------------------------------------------------------------------------
[2012-10-09 03:35:35] datibbaw@php.net
Reduced test:
$file = __DIR__ . '/input_dummy.txt';
$data = str_repeat( '.', 8189 ) . 'MMMM';
file_put_contents( $file, $data );
$fh = fopen( $file, "rb" );
$delimiter = "MM";
stream_get_line($fh, 4096, $delimiter);
stream_get_line($fh, 4096, $delimiter);
if ($delimiter === stream_get_line($fh, 4096, $delimiter)) {
echo "BROKEN";
} else {
echo "OK";
}
fclose($fh);
unlink($file);
The amount of dots seems to be related to the used buffer length:
(<number-of-dots> + 3) % (<buffer-length> x 2) == 0
The length of the delimiter also seems to play a role, but I'm not sure what
that would be.
------------------------------------------------------------------------
[2012-10-08 16:03:38] scope at planetavent dot de
Description:
------------
On specific file input stream_get_line returns a "line" that actually contains the
delimiter.
PHP 5.3.10 does not show this problem, PHP versions from 5.3.11 to 5.3.17 do. PHP 5.4.7 seems to be
affected as well.
Bug #44607 seems to be related, but was fixed long time ago.
Test script:
---------------
<?php
$file = __DIR__ . '/input_dummy.txt';
$data = str_repeat( '.', 8184 ) . 'MM' . str_repeat( '.', 8190 ) .
'MM' . str_repeat( '.', 8128 ) . 'MM' . str_repeat( '.', 61
) . 'MM' . str_repeat( '.', 20 );
file_put_contents( $file, $data );
$fh = fopen( $file, "rb" );
$delimiter = "MM";
while ( !feof( $fh ) )
{
$before = ftell( $fh );
$line = stream_get_line( $fh, 4096, $delimiter );
$after = ftell( $fh );
if ( strpos( $line, $delimiter ) !== false )
{
echo "found delimiter in return! ($before / $after)\n$line";
exit;
}
}
echo "ok\n";
Expected result:
----------------
ok
Actual result:
--------------
found delimiter in return! (24508 / 24591)
.............................................................MM....................
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63240&edit=1