|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-11-01 22:11 UTC] moron at industrial dot org
Description:
------------
A new safe_mode check has been added to PHP's GD library functions that affects image creation functions. The changed line is here:
ext/gd/gd.c:1647: if (!fn || fn == empty_string || php_check_open_basedir(fn TSRMLS_CC) || (PG(safe_mode) && !php_checkuid(fn, "rb+", CHECKUID_CHECK_FILE_AND_DIR))) {
As of 4.4.1 the following is new:
(PG(safe_mode) && !php_checkuid(fn, "rb+", CHECKUID_CHECK_FILE_AND_DIR))
Since this change GD is not able to create new images, presumably due to the above permissions check failing.
The problem with this code (if I am guessing what "php_checkuid" does correctly) is that it seems to make an invalid assumption as to how ownership works under Unix operating systems. Unless you run PHP as a CGI (running as the script owner), created files will always be owned by the generic web user ("www", "nobody", etc.). This means that the above check will fail since the ownership of the created file will not match that of the parent script.
What should be checked here is the group ownership and file level permissions since the owner will always be the web user (especially if the directory structure has been created on the fly).
As it stands, if you run under safe_mode and with PHP as a module under a Unix type system, you will always fail the safe_mode check and be unable to create images with the GD libraries.
Other file system functions appear to be unaffected (i.e. move_uploaded_file, copy, mkdir, etc.).
Cheers
Reproduce code:
---------------
<?php
// safe_mode is enabled
$img_out=imagecreatetruecolor(200,200);
imagejpeg($img_out,'files/thingy/test.jpg',100);
imagedestroy($img_out);
?>
Expected result:
----------------
new image created "files/thingy/test.jpg"
Actual result:
--------------
Warning: imagejpeg(): Unable to access files/thingy/test.jpg in /home/moron/www/test.php on line 3
Warning: imagejpeg(): Invalid filename 'files/thingy/test.jpg' in /home/moron/www/test.php on line 3
Here are the permissions in that directory:
drwxr-xrwx 15 nobody 12345 512 Sep 10 2004 files/thingy/
Here are the permissions on the script:
-rw-r--r-- 1 33300 12345 122 Nov 1 13:03 test.php
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 16 20:00:01 2025 UTC |
touch('files/thingy/test.jpg'); before imagejpeg worked for me