Clean up checking for properly extracted comics. Ensure better file name sanitization.
This commit is contained in:
parent
ab0dd508dc
commit
061c8afa2c
|
|
@ -23,25 +23,27 @@ if ( !$validated ) {
|
||||||
sendResponse();
|
sendResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isset($_REQUEST['comic']) ) {
|
if ( !isset($_REQUEST['comic']) ) {
|
||||||
$comicfull = realpath(COMICSDIR . base64_decode($_REQUEST['comic']));
|
$data["error"] = true;
|
||||||
|
$data["message"] = "Malformed request";
|
||||||
|
sendResponse();
|
||||||
|
}
|
||||||
|
$comicreq = base64_decode($_REQUEST['comic']);
|
||||||
|
$comicfile = basename($comicreq);
|
||||||
|
$comicpath = dirname($comicreq);
|
||||||
|
$comicfull = realpath(COMICSDIR . $comicreq);
|
||||||
if ( $comicfull === false ) {
|
if ( $comicfull === false ) {
|
||||||
$data["error"] = true;
|
$data["error"] = true;
|
||||||
$data["message"] = "Requested comic not found";
|
$data["message"] = "Requested comic not found";
|
||||||
sendResponse();
|
sendResponse();
|
||||||
}
|
}
|
||||||
$data["filename"] = basename($comicfull);
|
$data["filename"] = $comicfile;
|
||||||
$comic = substr($comicfull, strlen(COMICSDIR));
|
$comic = safeFileName(substr($comicfull, strlen(COMICSDIR)));
|
||||||
$comicoutputurl = "comics" . str_replace("#", "", $comic) . "/";
|
$comicoutputurl = "comics" . $comicpath . "/" . safeFileName($comicfile) . "/";
|
||||||
$comicoutputfull = "../" . EXTRACTSDIR . str_replace("#", "", $comic) . "/";
|
$comicoutputfull = "../" . EXTRACTSDIR . $comicpath . "/" . safeFileName($comicfile) . "/";
|
||||||
} else {
|
|
||||||
$data["error"] = true;
|
|
||||||
$data["message"] = "Malformed request";
|
|
||||||
sendResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
$ext = strtolower(substr($comicfull, -3));
|
$ext = strtolower(substr($comicfull, -3));
|
||||||
$_SESSION['comfile'] = basename($comicfull);
|
$_SESSION['comfile'] = $comicfile;
|
||||||
session_write_close();
|
session_write_close();
|
||||||
|
|
||||||
// Get the current page for this comic or 0 (zero) if never opened
|
// Get the current page for this comic or 0 (zero) if never opened
|
||||||
|
|
@ -92,7 +94,7 @@ if ( !$extracted ) {
|
||||||
if ( (substr($imgname, 0, 8) == "__MACOSX") || (substr($imgname, 0, 2) == "._") ) continue;
|
if ( (substr($imgname, 0, 8) == "__MACOSX") || (substr($imgname, 0, 2) == "._") ) continue;
|
||||||
$myext = strtolower(pathinfo($imgname)['extension']);
|
$myext = strtolower(pathinfo($imgname)['extension']);
|
||||||
if ( ! in_array($myext, VALIDIMAGETYPES) ) continue;
|
if ( ! in_array($myext, VALIDIMAGETYPES) ) continue;
|
||||||
$imgname = str_replace("#", "", $imgname);
|
$imgname = safeFileName($imgname);
|
||||||
$imgcontents = $zip->getFromIndex($i);
|
$imgcontents = $zip->getFromIndex($i);
|
||||||
$written = file_put_contents($comicoutputfull . $imgname, $imgcontents);
|
$written = file_put_contents($comicoutputfull . $imgname, $imgcontents);
|
||||||
if ( $written ) $files[] = $imgname;
|
if ( $written ) $files[] = $imgname;
|
||||||
|
|
@ -107,7 +109,7 @@ if ( !$extracted ) {
|
||||||
} else {
|
} else {
|
||||||
$entries = $rar->getEntries();
|
$entries = $rar->getEntries();
|
||||||
foreach ( $entries as $entry ) {
|
foreach ( $entries as $entry ) {
|
||||||
$outfile = str_replace("#", "", basename($entry->getName()));
|
$outfile = safeFileName(basename($entry->getName()));
|
||||||
if ( ! isset(pathinfo($outfile)['extension']) ) continue;
|
if ( ! isset(pathinfo($outfile)['extension']) ) continue;
|
||||||
if ( (substr($outfile, 0, 8) == "__MACOSX") || (substr($outfile, 0, 2) == "._") ) continue;
|
if ( (substr($outfile, 0, 8) == "__MACOSX") || (substr($outfile, 0, 2) == "._") ) continue;
|
||||||
$myext = strtolower(pathinfo($outfile)['extension']);
|
$myext = strtolower(pathinfo($outfile)['extension']);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user