1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-21 16:13:00 +00:00

unpacking: catch all possible errors from ZipArchive->open()

Thanks, @daveschroeter
For #249, but does NOT fix it
This commit is contained in:
Starbeamrainbowlabs 2023-10-12 00:51:25 +01:00
parent b8d68f411b
commit 7698290ee5
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
2 changed files with 45 additions and 3 deletions

View file

@ -6,7 +6,7 @@ This file holds the changelog for Pepperminty Wiki. This is the master list of t
This is the next release of Pepperminty Wiki, that hasn't been released yet. This is the next release of Pepperminty Wiki, that hasn't been released yet.
- **Fixed:** Fixed link to the interwiki links documentation on the help page if interwiki links have not yet been setup. - **Fixed:** Fixed link to the interwiki links documentation on the help page if interwiki links have not yet been setup.
- **Changed:** Catch and deal with more unpacking issues on first run (thanks, @daveschroeter in [#249](https://github.com/sbrl/Pepperminty-Wiki/issues/249))
## v0.24 ## v0.24
- **Added:** `filter` GET parameter to the `list` action, which filters the list of pages to contain only those containing the specified substring. - **Added:** `filter` GET parameter to the `list` action, which filters the list of pages to contain only those containing the specified substring.

View file

@ -49,13 +49,55 @@ if(!file_exists($paths->extra_data_directory) ||
if(!class_exists("ZipArchive") || !($extractor instanceof ZipArchive)) { if(!class_exists("ZipArchive") || !($extractor instanceof ZipArchive)) {
if(file_exists($paths->extra_data_directory)) if(file_exists($paths->extra_data_directory))
delete_recursive($paths->extra_data_directory); delete_recursive($paths->extra_data_directory);
exit(page_renderer::render_minimal("Unpacking error - $settings->sitename", "<p>Oops! $settings->sitename wasn't able to unpack itself because the ZipArchive doesn't exist or is faulty. Please install the PHP zip extension (on apt-based systems it's the <code>php-zip</code> package) and then try again later. You can check that it's installed by inspecting the output of <code>php -m</code>, or running the <a href='https://www.php.net/manual/en/function.phpinfo.php'><code>phpinfo()</code> command</a>.")); exit(page_renderer::render_minimal("Unpacking error - $settings->sitename", "<p>Oops! $settings->sitename wasn't able to unpack itself because the ZipArchive doesn't exist or is faulty. Please install the PHP zip extension (on apt-based systems it's the <code>php-zip</code> package) and then try again later. You can check that it's installed by inspecting the output of <code>php -m</code>, or running the <a href='https://www.php.net/manual/en/function.phpinfo.php'><code>phpinfo()</code> command</a>.</p>"));
}
$ex_error = $extractor->open($temp_filename);
if($ex_error !== true) {
if($ex_error !== false) {
switch ($ex_error) {
case ZipArchive::ER_EXISTS:
$ex_error = "A file already exists";
break;
case ZipArchive::ER_INCONS:
$ex_error = "The zip archive was inconsistent";
break;
case ZipArchive::ER_INVAL:
$ex_error = "An invalid argument was passed";
break;
case ZipArchive::ER_MEMORY:
$ex_error = "A malloc memory error occurred";
break;
case ZipArchive::ER_NOENT:
$ex_error = "No such file exists to open";
break;
case ZipArchive::ER_NOZIP:
$ex_error = "The file was not a zip archive";
break;
case ZipArchive::ER_READ:
$ex_error = "An error occurred when attempting to read the file";
break;
case ZipArchive::ER_SEEK:
$ex_error = "An error occurred when seeking while reading the file";
break;
default:
$ex_error = "An unknown error occurred (code $ex_error)";
break;
}
}
else {
$ex_error = "A generic and unidentifiable error occurred (code false)";
}
if(file_exists($paths->extra_data_directory))
delete_recursive($paths->extra_data_directory);
exit(page_renderer::render_minimal("Unpacking error - $settings->sitename", "<p>Oops! Unfortunately, $settings->sitename wasn't able to unpack itself properly. This is likely either a server misconfiguration or a bug. ZipArchive, the extractor class used by $settings->sitename says: ${ex_error}.</p>
<p>Please check that the <code>zip</code> extension is installed properly by inspecting the output of <code>php -m</code>, or running the <a href='https://www.php.net/manual/en/function.phpinfo.php'><code>phpinfo()</code> command</a> in a <code>.php</code> file on your webserver.</p>"));
} }
$extractor->open($temp_filename);
$extractor->extractTo($paths->extra_data_directory); $extractor->extractTo($paths->extra_data_directory);
$extractor->close(); $extractor->close();
unlink($temp_filename); unlink($temp_filename);
unset($ex_error);
unset($error_message_help); unset($error_message_help);
} }