From: vadim at vadiaz dot com
Operating system: Linux x86_64
PHP version: 5.2.5
PHP Bug Type: Zip Related
Bug description: wrong default cast for offset used in fseek
Description:
------------
zip extention failed to open zip files with thousands of files in root
directory on 64 bit Linux systems. From strace I seen than fseek get value
close to max_long.
After reviewing code I figured out that it caused by wrong default type
cast in php-5.2.5/ext/zip/lib/zip_open.c:313
fseek(fp, -(cd->size+cd->comment_len+EOCDLEN), SEEK_END);
which should be:
fseek(fp, -((long)(cd->size+cd->comment_len+EOCDLEN)), SEEK_END);
because on 64 bit systems long is 8 byte.
I aaplied following path and rebuild rpms for my CentOS 5 from scratch
which solves the problem
--- php-5.2.5/ext/zip/lib/zip_open.c.seek_error 2008-02-05
22:05:03.000000000 +0200
+++ php-5.2.5/ext/zip/lib/zip_open.c 2008-02-05 23:17:05.000000000
+0200
@@ -313,7 +313,7 @@
/* 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);
+ fseek(fp, -((long)(cd->size+cd->comment_len+EOCDLEN)), SEEK_END);
if (ferror(fp) || ((unsigned int)ftell(fp) != cd->offset)) {
/* seek error or offset of cdir wrong */
if (ferror(fp))
Reproduce code:
---------------
<html>
<head>
<title>Test of ZipArchive</title>
</head>
<body>
<?php
ini_set('display_errors','true');
include_once "/home/httpd/includes/general/zip0stream.php";
include "zip0://testSite.zip/f1/tst.php";
?>
</body>
</html>
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'
--
Edit bug report at http://bugs.php.net/?id=44055&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=44055&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=44055&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=44055&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=44055&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=44055&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=44055&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=44055&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=44055&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=44055&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=44055&r=support
Expected behavior: http://bugs.php.net/fix.php?id=44055&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=44055&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=44055&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=44055&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=44055&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=44055&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=44055&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=44055&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=44055&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=44055&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=44055&r=mysqlcfg