ID:               44607
 Updated by:       [EMAIL PROTECTED]
 Reported By:      amoo_miki at yahoo dot com
-Status:           Open
+Status:           Closed
 Bug Type:         Streams related
 Operating System: *
 PHP Version:      5CVS, 6CVS (2008-08-19)
 New Comment:

This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.




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

[2008-08-19 17:13:10] amoo_miki at yahoo dot com

Doing some more investigation:

if the "ending" is just a character, the function works fine and return
the correct value, always.

stream_get_line in ./ext/standard/streamfuncs.c passes the action to
php_stream_get_record in ./main/streams/streams.c where there is an
explicit condition:
if delim_len == 1 the result is directly fetched using memchr() else
php_memnstr() is requested to process the stream.
./main/php.h defines php_memnstr as zend_memnstr, and looking at
./Zend/zend_operatprs.h the function zend_memnstr uses memchr() and
memcmp() and I should suspect something going wrong there.

The patch that sometimes forces the function to work correctly is a
proof that all these functions work correct but there is a variable
whose value is not being set correctly, ie not being initialized
(maybe?)

Anyway, this function is a very useful one and it's really unfortunate
that it has not been fixed in almost 5 months.

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

[2008-08-19 15:30:10] amoo_miki at yahoo dot com

I just got PHP 6.0.0-dev (built: Jul 28 2008 02:06:04) also configured
and installed. that too has this problem of not working correctly.

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

[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-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

Reply via email to