|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-03-01 15:28 UTC] 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; PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 05:00:02 2025 UTC |
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 :-)> I assume it is similar on Windows. Yes. In this case the needed X-Bit (X = directory traversal) is still set. Thus you can "cd" to this directory. But on Windows we have an additional right RD (list directory). This one is not allowed, and so you can't do a "dir" in this directory. -> thus stat should normally work in this folder for own files. > Also sharing one temp for all vhost is not a wised idea :) If all vhosts have a (scripts are executed with a) different SID, that's not a problem. Only the creator SID (and admin/system) have full access to it own files in this folder, but no rights to files created from other SID's. (a little bit like 1777 on *nix. But an *nix you can still list other files. On Win not.) But back to the topic and let me extend the testscript: | <?php | $zipfile = tempnam(sys_get_temp_dir(), 'zip'); | $zip = new ZipArchive(); | | $res = $zip->open($zipfile, ZIPARCHIVE::CREATE); | if ($res !== true) { | printf("Can't create file (%d)", $res); | } | var_dump($res); | $zip->close(); | | $res = $zip->open($zipfile); | if ($res !== true) { | printf("Can't open file (%d)", $res); | } | | | unlink($zipfile); | ?> The result: | boolean true | Can't open file (11) I can create a new Zip-File in this folder, but can't open an existing one. BTW stat(). Here's an example with PHP stat() (and my favorite realpath): | <?php | $temp = tmpfile(); | $filedata = stream_get_meta_data($temp); | var_dump(stat($filedata['uri'])); | var_dump(realpath($filedata['uri'])); | ?> The result: | array (size=26) | 0 => int 2 | ... | boolean false tmpfile, fopen, stat, whatever is working in this dir. But realpath fails...