#49874 [NEW]: ftell()/fseek() inconsistency when using stream filters
| From: | jketterl at chipxonio dot de | Date: | Wed, 14 Oct 2009 11:39:40 +0000 |
| Subject: | #49874 [NEW]: ftell()/fseek() inconsistency when using stream filters | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-143559@lists.php.net to get a copy of this message | ||
From: jketterl at chipxonio dot de
Operating system: linux (ubuntu)
PHP version: 5.2.11
PHP Bug Type: Filesystem function related
Bug description: ftell()/fseek() inconsistency when using stream filters
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 bug report at http://bugs.php.net/?id=49874&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=49874&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=49874&r=trysnapshot53
Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=49874&r=trysnapshot60
Fixed in SVN: http://bugs.php.net/fix.php?id=49874&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=49874&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=49874&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=49874&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=49874&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=49874&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=49874&r=support
Expected behavior: http://bugs.php.net/fix.php?id=49874&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=49874&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=49874&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=49874&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=49874&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=49874&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=49874&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=49874&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=49874&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=49874&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=49874&r=mysqlcfg