|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-01-24 05:19 UTC] vadim at vadiaz dot com
Description:
------------
package totally broken on 64 bit systems
From strace I seen that it made seek far beyond zip archive
while opening it.
I look up code and found that there is wrong default type cast
See patch below
Reproduce code:
---------------
code used:
include_once "/home/httpd/includes/general/zip0stream.php";
include "zip0://testSite.zip/f1/tst.php";
patch:
--- zip-1.8.10/lib/zip_open.c 2007-05-22 12:32:32.000000000 +0300
+++ zip-1.8.10.1/lib/zip_open.c 2008-01-24 11:39:25.000000000 +0200
@@ -313,7 +313,8 @@
/* go to start of cdir and read it entry by entry */
bufp = NULL;
clearerr(fp);
- fseek(fp, -(cd->size+cd->comment_len+EOCDLEN), SEEK_END);
+ long seek_point = cd->size+cd->comment_len+EOCDLEN;
+ fseek(fp, -seek_point, SEEK_END);
if (ferror(fp) || ((unsigned int)ftell(fp) != cd->offset)) {
/* seek error or offset of cdir wrong */
if (ferror(fp))
Expected result:
----------------
<html>
<head>
<title>Test of ZipArchive</title>
</head>
<body>
<center><h1>ZipArchive works Ok</h1></center></body>
</html>
Actual result:
--------------
can not open stream 'zip0://testSite.zip/f1/tst.php'
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 07 17:00:02 2025 UTC |
there is a an ls output on archive file page and class it used: jim@proglot zip 103 $ ll testSite.zip -rwxrw-rw- 1 jim jim 2401954 2007-11-26 18:49 testSite.zip <html> <head> <title>Test of ZipArchive</title> </head> <body> <?php #ini_set('display_errors','true'); include_once "zip0stream.php"; include "zip0://testSite.zip/f1/tst.php"; ?> </body> </html> <? class ZIP0Stream { protected $zipPath; protected $zipArchive; //file specific info protected $position; protected $length; protected $content; protected $filePath; //dir specific info protected $dirPath; protected $curEntryNum; static protected $archives = array(); static public $debug = true; function __construct() { $this->stream_close(); $this->dir_closedir(); $this->zipArchive = false; $this->zipPath = ''; } public function stream_close() { $this->position = $this->length = 0; $this->content = ''; } public function stream_open($path, $mode, $options, &$opened_path) { if(self::$debug)echo "stream_open 1 $path $mode\n"; if(substr($mode,0,1) != 'r') { return false; } $components = parse_url($path); if(self::$debug)echo "stream_open 2 $components[scheme]\n"; if($components['scheme'] != 'zip0') { return false; } $this->filePath = substr($components['path'],1); $this->zipPath = $components['host']; if(self::$debug)echo "stream_open 3 $this->zipPath $this->filePath\n"; if(array_key_exists($this->zipPath, self::$archives)) { $this->zipArchive = self::$archives[$this->zipPath]; } else { $this->zipArchive = new ZipArchive(); if(($res = $this->zipArchive->open($this->zipPath)) !== true){ $this->zipArchive = false; self::$archives[$this->zipPath] = false; if(self::$debug)echo "error opening archive $this->zipPath error=$res\n"; return false; } self::$archives[$this->zipPath] = $this->zipArchive; } $fp = $this->zipArchive->getStream($this->filePath); if(!$fp) { if(self::$debug)echo "error getStream $this->zipPath $this->filePath\n"; return false; } while (!feof($fp)) { $this->content .= fread($fp, 4096); } $this->position = 0; $this->length = strlen($this->content); return true; } public function stream_read($count) { $count = min($count, $this->length - $this->position); if($count <= 0)return false; $pos = $this->position; $this->position += $count; return substr($this->content, $pos, $count); } public function stream_write($data) { return 0; } public function stream_tell() { return $this->position; } public function stream_eof() { return $this->position >= $this->length; } public function stream_seek($offset, $whence) { switch ($whence) { case SEEK_SET: $pos = 0; return false; case SEEK_CUR: $pos = $this->position; break; case SEEK_END: $pos = $this->length; break; default: return false; } $pos += $offset; if ($pos < $this->length && $pos >= 0) { $this->position = $pos; return true; } return false; } public function stream_flush(){ return false; } public function unlink($path){ return false; } public function stream_stat() { if(self::$debug)echo "stream_stat\n"; return false; } public function url_stat($path, $flags ) { if(self::$debug)echo "url_stat $path $flags\n"; return false; } public function rename($pathfrom, $pathto){ return false; } public function mkdir($path, $mode, $options ){ return false; } public function rmdir($path, $options ){ return false; } public function dir_opendir ($path, $options ) { if(self::$debug)echo "dir_opendir $path $flags\n"; return false; } public function dir_readdir () { //todo return false; } public function dir_rewinddir () { $this->curEntryNum = -1; return false; } public function dir_closedir () { $this->dirPath = ''; $this->curEntryNum = -1; return false; } } if (class_exists('ZIP0Stream') && !in_array('zip0', stream_get_wrappers())) { stream_wrapper_register('zip0', 'ZIP0Stream'); } ?>