php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33241 copy() sometime fail with permission error
Submitted: 2005-06-04 11:52 UTC Modified: 2005-06-06 10:24 UTC
From: kylewong at southa dot com Assigned:
Status: Not a bug Package: *Directory/Filesystem functions
PHP Version: 4.3.11 OS: linux kernel 2.6.10
Private report: No CVE-ID: None
 [2005-06-04 11:52 UTC] kylewong at southa dot com
Description:
------------
I have a script which unzip an uploaded ZIP file (contains image files) into a temp directory, "/dev/shm/tmp" (tmpfs for speed, I tried to use /tmp but still got the problem), which is owned by "nobody" and 777 in permission.

The script will then process the unzipped image files, one by one, by calling an resize_image() function.

The resize_image() function will try to resize the image, then copy the resized image to somewhere else.

The script works most of the time, but sometime, it failed with something like:

[04-Jun-2005 17:19:47] PHP Warning:  copy(/dev/shm/tmp/00800040.jpg): failed to open stream: Permission denied in /home/platform/fs_unix.php on line 15
[04-Jun-2005 17:19:48] PHP Warning:  copy(/dev/shm/tmp/00800041.jpg): failed to open stream: Permission denied in /home/platform/fs_unix.php on line 15
[04-Jun-2005 17:19:49] PHP Warning:  copy(/dev/shm/tmp/00800042.jpg): failed to open stream: Permission denied in /home/platform/fs_unix.php on line 15
[04-Jun-2005 17:19:50] PHP Warning:  copy(/dev/shm/tmp/00800043.jpg): failed to open stream: Permission denied in /home/platform/fs_unix.php on line 15
.....

when the error happens, all of the files insize the same zip file will result in same error.

I don't really know what's wrong since the scipt sometime works, sometime doesn't


Reproduce code:
---------------
util.php, $src will == $dest, $target is target size

function resize_image($src, $dest, $target) {
 
        if (!strcmp($src,$dest)) {
                $useTemp = true;
                $out = "$dest.tmp";
        }
        else {
                $out = $dest;
                $useTemp = false;
        }

/* resize xxx.jpg to xxx.jpg.tmp at the same directory */
$err = exec_wrapper("convert -quality 85 -size ${target}x${target} $src $out");
         
        if (file_exists("$out") && filesize("$out") > 0) {
                 if ($useTemp) {
//// copy back xxx.jpg.tmp to xxx.jpg ////
all errors happen here  ---> $ret = copy($out, $dest);
                        unlink($out);
                        if (!$ret){
                        return 0;
                        }
                        return 1;
                }
        } else {
                return 0;
        }
}
        

        

Expected result:
----------------
fs_copy() should not be failed with "permission denied" error

Actual result:
--------------
something failed with permission error

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-04 12:08 UTC] kylewong at southa dot com
all errors happen here  ---> $ret = copy($out, $dest);

should be:
all errors happen here  ---> $ret = fs_copy($out, $dest);

and /home/platform/fs_unix.php line 15
is just:
$result = copy($source, $dest);
 [2005-06-06 10:24 UTC] sniper@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Tue Aug 16 14:05:50 2022 UTC