patch secure: 3becc03d23
This commit is contained in:
parent
7b9597da2d
commit
e78d92c535
1 changed files with 77 additions and 77 deletions
|
|
@ -2,60 +2,60 @@
|
||||||
require_once("config.php");
|
require_once("config.php");
|
||||||
|
|
||||||
if (!function_exists('ft_nonce_is_valid')) {
|
if (!function_exists('ft_nonce_is_valid')) {
|
||||||
include_once "../editor.lib.php";
|
include_once('../editor.lib.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!function_exists('che_reprocessImage')) {
|
if (!function_exists('che_reprocessImage')) {
|
||||||
function che_reprocessImage($file_path, $callback)
|
function che_reprocessImage($file_path, $callback)
|
||||||
{
|
{
|
||||||
$MIME_TYPES_PROCESSORS = array(
|
$MIME_TYPES_PROCESSORS = array(
|
||||||
"image/gif" => array("imagecreatefromgif", "imagegif"),
|
"image/gif" => ["imagecreatefromgif", "imagegif"],
|
||||||
"image/jpg" => array("imagecreatefromjpeg", "imagejpeg"),
|
"image/jpg" => ["imagecreatefromjpeg", "imagejpeg"],
|
||||||
"image/jpeg" => array("imagecreatefromjpeg", "imagejpeg"),
|
"image/jpeg" =>["imagecreatefromjpeg", "imagejpeg"],
|
||||||
"image/png" => array("imagecreatefrompng", "imagepng"),
|
"image/png" => ["imagecreatefrompng", "imagepng"],
|
||||||
"image/webp" => array("imagecreatefromwebp", "imagewebp"),
|
"image/webp" =>["imagecreatefromwebp", "imagewebp"],
|
||||||
"image/bmp" => array("imagecreatefromwbmp", "imagewbmp")
|
"image/bmp" => ["imagecreatefromwbmp", "imagewbmp"],
|
||||||
);
|
);
|
||||||
|
|
||||||
// Extracting mime type using getimagesize
|
// Extracting mime type using getimagesize
|
||||||
try {
|
try {
|
||||||
$image_info = getimagesize($file_path);
|
$image_info = getimagesize($file_path);
|
||||||
if ($image_info === null) {
|
if ($image_info === null) {
|
||||||
//throw new Exception("Invalid image type");
|
//throw new Exception("Invalid image type");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$mime_type = $image_info["mime"];
|
$mime_type = $image_info["mime"];
|
||||||
|
|
||||||
if (!array_key_exists($mime_type, $MIME_TYPES_PROCESSORS)) {
|
if (!array_key_exists($mime_type, $MIME_TYPES_PROCESSORS)) {
|
||||||
//throw new Exception("Invalid image MIME type");
|
//throw new Exception("Invalid image MIME type");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$image_from_file = $MIME_TYPES_PROCESSORS[$mime_type][0];
|
$image_from_file = $MIME_TYPES_PROCESSORS[$mime_type][0];
|
||||||
$image_to_file = $MIME_TYPES_PROCESSORS[$mime_type][1];
|
$image_to_file = $MIME_TYPES_PROCESSORS[$mime_type][1];
|
||||||
|
|
||||||
$reprocessed_image = @$image_from_file($file_path);
|
$reprocessed_image = @$image_from_file($file_path);
|
||||||
|
|
||||||
if (!$reprocessed_image) {
|
if (!$reprocessed_image) {
|
||||||
//throw new Exception("Unable to create reprocessed image from file");
|
//throw new Exception("Unable to create reprocessed image from file");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calling callback(if set) with path of image as a parameter
|
// Calling callback(if set) with path of image as a parameter
|
||||||
if ($callback !== null) {
|
if ($callback !== null) {
|
||||||
$callback($reprocessed_image);
|
$callback($reprocessed_image);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Freeing up memory
|
// Freeing up memory
|
||||||
imagedestroy($reprocessed_image);
|
imagedestroy($reprocessed_image);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
unlink($file_path);
|
unlink($file_path);
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$is_editor_upload = false;
|
$is_editor_upload = false;
|
||||||
|
|
@ -63,11 +63,11 @@ $is_editor_upload = false;
|
||||||
$get_nonce = get_session('nonce_' . FT_NONCE_SESSION_KEY);
|
$get_nonce = get_session('nonce_' . FT_NONCE_SESSION_KEY);
|
||||||
|
|
||||||
if ($get_nonce && ft_nonce_is_valid($get_nonce, 'cheditor')) {
|
if ($get_nonce && ft_nonce_is_valid($get_nonce, 'cheditor')) {
|
||||||
$is_editor_upload = true;
|
$is_editor_upload = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$is_editor_upload) {
|
if (!$is_editor_upload) {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
run_event('cheditor_photo_upload', $data_dir, $data_url);
|
run_event('cheditor_photo_upload', $data_dir, $data_url);
|
||||||
|
|
@ -81,16 +81,16 @@ $filename_len = strrpos($filename, ".");
|
||||||
$type = substr($filename, strrpos($filename, ".") + 1);
|
$type = substr($filename, strrpos($filename, ".") + 1);
|
||||||
$found = false;
|
$found = false;
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case "jpg":
|
case "jpg":
|
||||||
case "jpeg":
|
case "jpeg":
|
||||||
case "gif":
|
case "gif":
|
||||||
case "png":
|
case "png":
|
||||||
case "webp":
|
case "webp":
|
||||||
$found = true;
|
$found = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($found != true || $filename_len != 23) {
|
if ($found != true || $filename_len != 23) {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 저장 파일 이름: 년월일시분초_렌덤문자8자
|
// 저장 파일 이름: 년월일시분초_렌덤문자8자
|
||||||
|
|
@ -105,50 +105,50 @@ $imgsize = getimagesize($savefile);
|
||||||
$filesize = filesize($savefile);
|
$filesize = filesize($savefile);
|
||||||
|
|
||||||
if (!$imgsize) {
|
if (!$imgsize) {
|
||||||
$filesize = 0;
|
$filesize = 0;
|
||||||
$random_name = '-ERR';
|
$random_name = '-ERR';
|
||||||
unlink($savefile);
|
unlink($savefile);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CHE_UPLOAD_IMG_CHECK && !che_reprocessImage($savefile, null)) {
|
if (CHE_UPLOAD_IMG_CHECK && !che_reprocessImage($savefile, null)) {
|
||||||
$filesize = 0;
|
$filesize = 0;
|
||||||
$random_name = '-ERR';
|
$random_name = '-ERR';
|
||||||
unlink($savefile);
|
unlink($savefile);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (defined('G5_FILE_PERMISSION')) {
|
if (defined('G5_FILE_PERMISSION')) {
|
||||||
chmod($savefile, G5_FILE_PERMISSION);
|
chmod($savefile, G5_FILE_PERMISSION);
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$file_url = SAVE_URL . '/' . $filename;
|
$file_url = SAVE_URL . '/' . $filename;
|
||||||
|
|
||||||
if (function_exists('run_replace')) {
|
if (function_exists('run_replace')) {
|
||||||
$fileInfo = new \stdClass();
|
$fileInfo = new \stdClass();
|
||||||
$fileInfo->name = (string) $filename;
|
$fileInfo->name = (string) $filename;
|
||||||
$fileInfo->size = (int) $filesize;
|
$fileInfo->size = (int) $filesize;
|
||||||
$fileInfo->url = (string) $file_url;
|
$fileInfo->url = (string) $file_url;
|
||||||
|
|
||||||
if (isset($_POST['origname'])) {
|
if (isset($_POST['origname'])) {
|
||||||
$fileInfo->oriname = (string) $_POST['origname'];
|
$fileInfo->oriname = (string) $_POST['origname'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($imgsize) {
|
if ($imgsize) {
|
||||||
$fileInfo->width = (int) $imgsize[0];
|
$fileInfo->width = (int) $imgsize[0];
|
||||||
$fileInfo->height = (int) $imgsize[1];
|
$fileInfo->height = (int) $imgsize[1];
|
||||||
$fileInfo->type = (string) $imgsize['mime'];
|
$fileInfo->type = (string) $imgsize['mime'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$file_url = run_replace('get_editor_upload_url', $file_url, $savefile, $fileInfo);
|
$file_url = run_replace('get_editor_upload_url', $file_url, $savefile, $fileInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
$rdata = sprintf(
|
$rdata = sprintf(
|
||||||
'{"fileUrl": "%s", "fileName": "%s", "fileSize": "%d" }',
|
'{"fileUrl": "%s", "fileName": "%s", "fileSize": "%d" }',
|
||||||
$file_url,
|
$file_url,
|
||||||
$filename,
|
$filename,
|
||||||
$filesize
|
$filesize
|
||||||
);
|
);
|
||||||
|
|
||||||
echo $rdata;
|
echo $rdata;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue