Switch to testing image types against defined array of valid options

This commit is contained in:
Junior 2026-03-10 21:25:09 -04:00
parent 1dd3a3bc70
commit 5d3db365b4
3 changed files with 10 additions and 12 deletions

View File

@ -69,7 +69,7 @@ if ( $extracted ) {
//$myext = substr($imgname, -3); //$myext = substr($imgname, -3);
if ( ! isset(pathinfo($imgname)['extension']) ) continue; if ( ! isset(pathinfo($imgname)['extension']) ) continue;
$myext = strtolower(pathinfo($imgname)['extension']); $myext = strtolower(pathinfo($imgname)['extension']);
if ( ($myext == "jpeg") || ($myext == "jpg") || ($myext == "png") || ($myext == "webp") ) { if ( in_array($myext, VALIDIMAGETYPES) ) {
$imgname = str_replace("#", "", $imgname); $imgname = str_replace("#", "", $imgname);
$imgcontents = $zip->getFromIndex($i); $imgcontents = $zip->getFromIndex($i);
$written = file_put_contents($comicoutputfull . $imgname, $imgcontents); $written = file_put_contents($comicoutputfull . $imgname, $imgcontents);
@ -84,7 +84,7 @@ if ( $extracted ) {
$entry->extract(false, $comicoutputfull . $outfile); $entry->extract(false, $comicoutputfull . $outfile);
if ( ! isset(pathinfo($outfile)['extension']) ) continue; if ( ! isset(pathinfo($outfile)['extension']) ) continue;
$myext = strtolower(pathinfo($outfile)['extension']); $myext = strtolower(pathinfo($outfile)['extension']);
if ( ($myext == "jpeg") || ($myext == "jpg") || ($myext == "png") || ($myext == "webp") ) { if ( in_array($myext, VALIDIMAGETYPES) ) {
$files[] = basename($outfile); $files[] = basename($outfile);
} }
} }

View File

@ -43,3 +43,4 @@ define('DBNAME', 'comics');
define('SORTBYNAME', "Name"); define('SORTBYNAME', "Name");
define('SORTBYDATE', "Date"); define('SORTBYDATE', "Date");
define('SORTBYREAD', "Read"); define('SORTBYREAD', "Read");
define('VALIDIMAGETYPES', array("jpg", "jpeg", "gif", "png", "webp"));

View File

@ -14,6 +14,11 @@ function getAdultComics() {
return $adultcomics; return $adultcomics;
} }
function safeFileName($file = "") {
$to_remove = array("<", ">", "#", "\"", "/", "\\", "*", "?", "|");
return str_replace($to_remove, '', $file);
}
function makeThumb($item = "") { function makeThumb($item = "") {
if ( $item == "" ) { return false; } if ( $item == "" ) { return false; }
$prefix = (substr(getcwd(), -4) == "ajax") ? "../" : ""; $prefix = (substr(getcwd(), -4) == "ajax") ? "../" : "";
@ -57,11 +62,7 @@ function makeThumb($item = "") {
$parts = pathinfo($imgname); $parts = pathinfo($imgname);
if ( isset($parts['extension']) ) { if ( isset($parts['extension']) ) {
$imgext = strtolower($parts['extension']); $imgext = strtolower($parts['extension']);
if ( (strcmp($lowest, $imgname) > 0) if ( (strcmp($lowest, $imgname) > 0) && in_array($imgext, VALIDIMAGETYPES) ) {
&& ((strcasecmp($imgext, "jpg") == 0)
|| (strcasecmp($imgext, "jpeg") == 0)
|| (strcasecmp($imgext, "png") == 0)
|| (strcasecmp($imgext, "webp") == 0)) ) {
$lowest = $imgname; $lowest = $imgname;
$imgdata = $zip->getFromIndex($i); $imgdata = $zip->getFromIndex($i);
} }
@ -81,11 +82,7 @@ function makeThumb($item = "") {
$parts = pathinfo($imgname); $parts = pathinfo($imgname);
if ( isset($parts['extension']) ) { if ( isset($parts['extension']) ) {
$imgext = strtolower($parts['extension']); $imgext = strtolower($parts['extension']);
if ( (strcmp($lowest, $imgname) > 0) if ( (strcmp($lowest, $imgname) > 0) && in_array($imgext, VALIDIMAGETYPES) ) {
&& ((strcasecmp($imgext, "jpg") == 0)
|| (strcasecmp($imgext, "jpeg") == 0)
|| (strcasecmp($imgext, "png") == 0)
|| (strcasecmp($imgext, "webp") == 0)) ) {
$lowest = $imgname; $lowest = $imgname;
$didwrite = $entry->extract(false, $outfile); $didwrite = $entry->extract(false, $outfile);
if ( !$didwrite ) { return false; } if ( !$didwrite ) { return false; }