From: Greg Beaver Date: Sat, 11 Oct 2008 22:21:07 +0000 (+0000) Subject: MFB: fix links for fseek as well X-Git-Tag: BEFORE_HEAD_NS_CHANGE~247 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=692222f12a42584bde52c68257068f79ed260454;p=php MFB: fix links for fseek as well --- diff --git a/ext/phar/stream.c b/ext/phar/stream.c index 95950bf60f..6670f6d48c 100644 --- a/ext/phar/stream.c +++ b/ext/phar/stream.c @@ -389,12 +389,19 @@ static size_t phar_stream_read(php_stream *stream, char *buf, size_t count TSRML static int phar_stream_seek(php_stream *stream, off_t offset, int whence, off_t *newoffset TSRMLS_DC) /* {{{ */ { phar_entry_data *data = (phar_entry_data *)stream->abstract; - + phar_entry_info *entry; int res; off_t temp; + + if (data->internal_file->link) { + entry = phar_get_link_source(data->internal_file TSRMLS_CC); + } else { + entry = data->internal_file; + } + switch (whence) { case SEEK_END : - temp = data->zero + data->internal_file->uncompressed_filesize + offset; + temp = data->zero + entry->uncompressed_filesize + offset; break; case SEEK_CUR : temp = data->zero + data->position + offset; @@ -403,7 +410,7 @@ static int phar_stream_seek(php_stream *stream, off_t offset, int whence, off_t temp = data->zero + offset; break; } - if (temp > data->zero + (off_t) data->internal_file->uncompressed_filesize) { + if (temp > data->zero + (off_t) entry->uncompressed_filesize) { *newoffset = -1; return -1; } diff --git a/ext/phar/tests/tar/links6.phpt b/ext/phar/tests/tar/links6.phpt index 622a8b61bf..9a548a8784 100644 --- a/ext/phar/tests/tar/links6.phpt +++ b/ext/phar/tests/tar/links6.phpt @@ -9,6 +9,10 @@ if (!extension_loaded("phar")) die("skip"); echo file_get_contents('phar://' . dirname(__FILE__) . '/files/links.phar.tar/link2'); echo file_get_contents('phar://' . dirname(__FILE__) . '/files/links.phar.tar/link1'); echo file_get_contents('phar://' . dirname(__FILE__) . '/files/links.phar.tar/testit.txt'); + +$a = fopen('phar://' . dirname(__FILE__) . '/files/links.phar.tar/link2', 'r'); +fseek($a, 3); +echo fread($a, 10); ?> ===DONE=== --EXPECT-- @@ -18,4 +22,6 @@ hi there hi there +there + ===DONE=== \ No newline at end of file