Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
* Fix #2979 : Better security when upload an image
Browse files Browse the repository at this point in the history
  • Loading branch information
leoncx committed Aug 4, 2015
1 parent b11c0c8 commit 60a817a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
11 changes: 6 additions & 5 deletions www/include/options/media/images/DB-Func.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function isValidImage($filename) {
return false;
$imginfo = getimagesize($filename);

if (isset($imginfo)) {
if (isset($imginfo) && false !== $imginfo) {
return true;
} else {
return is_gd2($filename);
Expand Down Expand Up @@ -125,8 +125,9 @@ function handleUpload($HTMLfile, $dir_alias, $img_comment = "") {
foreach ($filelist as $file) {
if (is_dir($uploaddir.$file))
continue; // skip directories in list
if (!isValidImage($uploaddir.$file))
continue;
if (!isValidImage($uploaddir.$file)) {
return false;
}
if (is_gd2($uploaddir.$file)) {
$im = imagecreatefromgd2($uploaddir.$file);
if (preg_match('/gd2$/', $file)) {
Expand Down Expand Up @@ -229,7 +230,7 @@ function deleteImg ($img_id) {

function updateImg($img_id, $HTMLfile, $dir_alias, $img_name, $img_comment) {
if (!$img_id)
return;
return false;
global $pearDB;
$mediadir = "./img/media/";
$uploaddir = "../filesUpload/images/";
Expand All @@ -243,7 +244,7 @@ function updateImg($img_id, $HTMLfile, $dir_alias, $img_name, $img_comment) {
$rq .= " WHERE img_id = '".$img_id."' AND img_id = img_img_id AND dir_dir_parent_id = dir_id";
$DBRESULT = $pearDB->query($rq);
if (!$DBRESULT)
return;
return false;
$img_info = $DBRESULT->fetchRow();

if ($dir_alias)
Expand Down
14 changes: 7 additions & 7 deletions www/include/options/media/images/formImg.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,16 @@
$imgID = $form->getElement('img_id');
$imgPath = $form->getElement('directories')->getValue();
$imgComment = $form->getElement('img_comment')->getValue();
if ($form->getSubmitValue("submitA"))
handleUpload($file, $imgPath, $imgComment);
else if ($form->getSubmitValue("submitC")) {
if ($form->getSubmitValue("submitA")) {
$valid = handleUpload($file, $imgPath, $imgComment);
} else if ($form->getSubmitValue("submitC")) {
$imgName = $form->getElement('img_name')->getValue();
updateImg($imgID->getValue(), $file, $imgPath, $imgName, $imgComment);
$valid = updateImg($imgID->getValue(), $file, $imgPath, $imgName, $imgComment);
}
$o = NULL;
$form->addElement("button", "change", _("Modify"), array("onClick"=>"javascript:window.location.href='?p=".$p."&o=ci&img_id=".$imgID->getValue()."'"));
$form->freeze();
$valid = true;
if (false === $valid) {
$form->setElementError('filename', "An image is not uploaded.");
}
}
$action = $form->getSubmitValue("action");

Expand Down

0 comments on commit 60a817a

Please sign in to comment.