Skip to content

Commit

Permalink
Adding check for thumbnail location
Browse files Browse the repository at this point in the history
  • Loading branch information
marekrei committed Dec 2, 2024
1 parent 1807c61 commit 50dc54e
Showing 1 changed file with 32 additions and 17 deletions.
49 changes: 32 additions & 17 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -1828,6 +1828,9 @@ public static function openPdf($file)
if(!ImageServer::isEnabledPdf())
return null;

if(!ImageServer::isAllowedToOpenPath($file))
return null;

$im = new Imagick($file.'[0]');
$im->setImageFormat( "png" );
$str = $im->getImageBlob();
Expand Down Expand Up @@ -1915,30 +1918,42 @@ public static function showThumbnail($file)
imagepng($image);
}
}

public static function isAllowedToOpenPath($file)
{
if(realpath($file) && str_starts_with(realpath($file), realpath($_CONFIG['starting_dir'])))
return true;
return false;
}

//
// A helping function for opening different types of image files
//
public static function openImage ($file)
{
$size = getimagesize($file);
switch($size["mime"])
{
case "image/jpeg":
$im = imagecreatefromjpeg($file);
break;
case "image/gif":
$im = imagecreatefromgif($file);
break;
case "image/png":
$im = imagecreatefrompng($file);
break;
default:
$im=null;
break;
}
if(!ImageServer::isAllowedToOpenPath($file))
return null;

$im = null;
$size = getimagesize($file);
switch($size["mime"])
{
case "image/jpeg":
$im = imagecreatefromjpeg($file);
break;
case "image/gif":
$im = imagecreatefromgif($file);
break;
case "image/png":
$im = imagecreatefrompng($file);
break;
default:
$im = null;
break;
}
return $im;
}

}

//
Expand Down Expand Up @@ -3206,7 +3221,7 @@ function(){
if($file->isValidForThumb())
print " thumb";
print "\"";
print "WOOOO".EncodeExplorer::getConfig('force_download');
print " ".EncodeExplorer::getConfig('force_download');
if(EncodeExplorer::getConfig('force_download') == true)
print " download";
print ">";
Expand Down

0 comments on commit 50dc54e

Please sign in to comment.