Bug #66638 [Opn->Nab]: Using SEEK_CUR to seek before start in php://memory produces incorrect results
Edit report at https://bugs.php.net/bug.php?id=66638&edit=1
ID: 66638
Updated by: krakjoe@php.net
Reported by: madhusudancs at gmail dot com
Summary: Using SEEK_CUR to seek before start in php://memory
produces incorrect results
-Status: Open
+Status: Not a bug
Type: Bug
Package: Streams related
Operating System: Linux (likely all)
PHP Version: master-Git-2014-02-03 (Git)
Block user comment: N
Private report: N
New Comment:
The second call to fseek returns -1, which you should be checking for, you get unexpected results as
a result of not checking return values.
I'm not sure why you expect to be able to read before the start of a memory stream, but this
isn't a bug, the code is wrong.
Previous Comments:
------------------------------------------------------------------------
[2014-02-04 02:00:47] madhusudancs at gmail dot com
Updating the summary line
------------------------------------------------------------------------
[2014-02-03 23:58:25] madhusudancs at gmail dot com
Description:
------------
When using php://memory stream, attempting to seek behind the start position, produces incorrect
results.
Sample test case below (in the next field)
Test case should print the entire stream (all the bytes in the stream, but it prints an empty
string.
Test script:
---------------
<?php
$fh = fopen('php://memory', 'w');
for ($ii = 0; $ii < 10; $ii++) {
fwrite($fh, "[$ii] hello world. ");
}
$sz = 170;
fseek($fh, $sz - 100, SEEK_SET);
fseek($fh, -$sz, SEEK_CUR);
var_dump(fread($fh, $sz));
?>
Expected result:
----------------
string(170) "[0] hello world. [1] hello world. [2] hello world. [3] hello world. [4] hello
world. [5] hello world. [6] hello world. [7] hello world. [8] hello world. [9] hello world. "
Actual result:
--------------
string(0) ""
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66638&edit=1
Thread (3 messages)