我想知道来自and的函数imagecreatefrompng (和它的相关函数)是否安全?
例如,如果我使用此函数获取外部图像文件,并且图像包含恶意代码,则此代码会在我的服务器上执行吗?
示例:
<?php
if($_GET['pass'] != 'IamAW') die();
// Accepted Filetypes
$Accepted = array('png');
$File = $_GET['file'];
$Filetype = end(explode('.', $File));
if(!in_array($Filetype, $Accepted)) {
die('Fil-type ikke valid');
}
$im = imagecreatefrompng($File);
header('Content-Type: image/'. $Filetype);
imagepng($im);
imagedestroy($im);
?>发布于 2014-10-30 03:13:15
这是可行的,但为什么还要费心呢?
您正在吸收一个远程PNG,在内存中解压缩为原始格式,然后重新压缩为PNG,而无需对图像做任何操作。如果它最终是一个“大”的PNG (例如,一个1280x1024 32位的PNG需要5兆字节的内存),你就有耗尽内存的风险。
你最好这样做:
echo file_get_contents($remote_image_url);为您节省解压缩/重新压缩的时间。
https://stackoverflow.com/questions/26638417
复制相似问题