#49874 [Opn->Bgs]: ftell()/fseek() inconsistency when using stream filters
| From: | Sjoerd@php.net | Date: | Wed, 14 Oct 2009 16:40:00 +0000 |
| Subject: | #49874 [Opn->Bgs]: ftell()/fseek() inconsistency when using stream filters | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-143566@lists.php.net to get a copy of this message | ||
ID: 49874
Updated by: Sjoerd@php.net
Reported By: jketterl at chipxonio dot de
-Status: Open
+Status: Bogus
Bug Type: Filesystem function related
Operating System: linux (ubuntu)
PHP Version: 5.2.11
New Comment:
Thank you for your bug report. Does your test.csv file start with a
BOM? You can determine this by viewing the file in a hex editor. If it
starts with fffe or feff, it has a BOM (byte order mark).
Previous Comments:
------------------------------------------------------------------------
[2009-10-14 11:39:39] jketterl at chipxonio dot de
Description:
------------
exact php version: PHP 5.2.11-0.dotdeb.1 with Suhosin-Patch 0.9.7 (cli)
(built: Sep 20 2009 09:41:43)
this bug is also be filter-/stream-related. i just believe it might be
easier to fix on the filesystem side, that's why i chose that category.
when using a php stream filter to convert input from utf-16 into
iso8859 (or most probably from any 2byte-encoded charset into any
single-byte-encode charset) the ftell() and fseek() functions start to
behave inconsistently.
more precisely: fseek() jumps to exact offsets ignoring the
2byte-encoding, whereas ftell() seems to return the number of bytes read
*after* the filter has been applied. thus it is not possible to fseek()
back to a certain offset that has been stored with ftell() before.
the content of the testfile used in the code examples is as follows:
Line 01
Line 02
Line 03
Line 04
Reproduce code:
---------------
$file = 'test.csv';
$fp = fopen($file, 'r');
stream_filter_append($fp, 'convert.iconv.utf16/iso8859-15');
$line = fgets($fp);
var_dump($line);
$line = fgets($fp);
var_dump($line);
fclose($fp);
$fp = fopen($file, 'r');
stream_filter_append($fp, 'convert.iconv.utf16/iso8859-15');
$line = fgets($fp);
var_dump($line);
fseek($fp, ftell($fp)); // this shouldn't move anything - but it
does...
$line = fgets($fp);
var_dump($line);
fclose($fp);
Expected result:
----------------
string(8) "Line 01
"
string(8) "Line 02
"
string(8) "Line 01
"
string(8) "Line 02
"
Actual result:
--------------
string(8) "Line 01
"
string(8) "Line 02
"
string(8) "Line 01
"
string(4) " 01
"
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=49874&edit=1