Edit report at http://bugs.php.net/bug.php?id=54128&edit=1

 ID:                 54128
 User updated by:    vavra at 602 dot cz
 Reported by:        vavra at 602 dot cz
 Summary:            ZIP_ER_OPEN when ZipArchive::open() on temp file
 Status:             Assigned
 Type:               Bug
 Package:            Zip Related
 Operating System:   Windows 2003
 PHP Version:        5.2.17
 Assigned To:        pajoye
 Block user comment: N
 Private report:     N

 New Comment:

Well, I've made another test. I've written a small c program compiled by
VC9 containing calls of stat and fopen. In php I've called this program
via exec(). When IUSR_XXXX has no right to list the temp folder the
result was: stat() failed with -1, fopen succeeded.



So I think function _zip_file_exists() in zip/lib/zip_open.c should be
rewritten. Instead of calling stat, it should be called fopen. Stat
calls is made only for existence detection, no fields from struct stat
are read. So you can replace stat without any limitations and users of
ZipArchive::open will no longer be confused by behaviour of stat
function.


Previous Comments:
------------------------------------------------------------------------
[2011-03-01 15:55:09] johan...@php.net

I assume this is expected bahvior. At least on UNIX/Linux systems stat
is defined as



     The stat()  function  obtains  information  about  the  file

     pointed  to  by  path. Read, write, or execute permission of

     the named file is not required, but all  directories  listed

     in the path name leading to the file must be searchable.



I assume it is similar on Windows.



If the zip extension is accessing the temp dir this should probably be
documented.



Assigning to Pierre who knows zip and windows better :-)

------------------------------------------------------------------------
[2011-03-01 15:28:53] vavra at 602 dot cz

Description:
------------
On Windows 2003, IIS we use php as CGI. The php process runs as a
IUSR_XXXX user. When we want to unzip a file, we get error 11
(ZIP_ER_OPEN).



I tracked this by Process Monitor and I saw that ZipArchive::open()
tries to list a directory. We use temp directory. On Windows 2003 it is
C:\Windows\Temp.

After listing this directory ZipArchive::open() returns 11. And doesn't
continue at work.



When I add right "List Folder" for user IUSR_XXXX the open() call
succeeds.

I think it should be a kind of bug of c-runtime. I searched for
ZIP_ER_OPEN in php source and this is returned nearly after calls of
fopen() and stat(). It's odd that fopen() and stat() makes directory
listing....





Test script:
---------------
//without result testing:



$zipfile = tempnam(sys_get_temp_dir(),'zip');

file_put_contents($zipfile, $a_zip_file_content);

$zip = new ZipArchive();



$a_zip_file_content_reread = file_get_contents($zipfile,
$a_zip_file_conent);

//$a_zip_file_conent_reread has bean successfully read and has the same
content as $a_zip_file_content





$res=$zip->open($zipfile);

if ($res!==true)

 echo "Failed open a file: ".$res;





------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=54128&edit=1

Reply via email to