diff --git a/ajax/showcomic.php b/ajax/showcomic.php index f973b2c..52c6d2d 100644 --- a/ajax/showcomic.php +++ b/ajax/showcomic.php @@ -23,25 +23,27 @@ if ( !$validated ) { sendResponse(); } -if ( isset($_REQUEST['comic']) ) { - $comicfull = realpath(COMICSDIR . base64_decode($_REQUEST['comic'])); - if ( $comicfull === false ) { - $data["error"] = true; - $data["message"] = "Requested comic not found"; - sendResponse(); - } - $data["filename"] = basename($comicfull); - $comic = substr($comicfull, strlen(COMICSDIR)); - $comicoutputurl = "comics" . str_replace("#", "", $comic) . "/"; - $comicoutputfull = "../" . EXTRACTSDIR . str_replace("#", "", $comic) . "/"; -} else { +if ( !isset($_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 ) { + $data["error"] = true; + $data["message"] = "Requested comic not found"; + sendResponse(); +} +$data["filename"] = $comicfile; +$comic = safeFileName(substr($comicfull, strlen(COMICSDIR))); +$comicoutputurl = "comics" . $comicpath . "/" . safeFileName($comicfile) . "/"; +$comicoutputfull = "../" . EXTRACTSDIR . $comicpath . "/" . safeFileName($comicfile) . "/"; $ext = strtolower(substr($comicfull, -3)); -$_SESSION['comfile'] = basename($comicfull); +$_SESSION['comfile'] = $comicfile; session_write_close(); // 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; $myext = strtolower(pathinfo($imgname)['extension']); if ( ! in_array($myext, VALIDIMAGETYPES) ) continue; - $imgname = str_replace("#", "", $imgname); + $imgname = safeFileName($imgname); $imgcontents = $zip->getFromIndex($i); $written = file_put_contents($comicoutputfull . $imgname, $imgcontents); if ( $written ) $files[] = $imgname; @@ -107,7 +109,7 @@ if ( !$extracted ) { } else { $entries = $rar->getEntries(); foreach ( $entries as $entry ) { - $outfile = str_replace("#", "", basename($entry->getName())); + $outfile = safeFileName(basename($entry->getName())); if ( ! isset(pathinfo($outfile)['extension']) ) continue; if ( (substr($outfile, 0, 8) == "__MACOSX") || (substr($outfile, 0, 2) == "._") ) continue; $myext = strtolower(pathinfo($outfile)['extension']);