1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-11-22 04:23:01 +00:00

Use tempnam() instead of tmpfile() when unpacking extra data

It seems that some people were experiencing some strange issues with 
stream_get_meta_data($handle)["uri"] - hrm 🤔
This commit is contained in:
Starbeamrainbowlabs 2019-09-11 23:44:59 +01:00
parent dcd3c00d83
commit 3ab0d6dba2
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
2 changed files with 8 additions and 9 deletions

View file

@ -31,6 +31,7 @@ This file holds the changelog for Pepperminty Wiki. This is the master list of t
- The server's `expose_php` setting is respected - if it's disabled, then the PHP version will not be exposed.
- Pepperminty Wiki _shouldn't_ make remote requests without you asking it to - see above and the theme gallery
- Improved peppermint.json.compromised error message - if it's still unclear, please let me know
- Fiddled with the extra data extractor, as it seems that some people were experiencing strange issues with `stream_get_meta_data()`
## v0.19.2-hotfix2

View file

@ -23,10 +23,11 @@ if(!file_exists($paths->extra_data_directory) ||
exit(page_renderer::render_minimal("Unpacking error - $settings->sitename", "<p>Oops! It looks like $settings->sitename isn't able to change the last modified time of the extra data directory.</p>$error_message_help"));
}
$temp_file = tmpfile();
$temp_filename = tempnam(sys_get_temp_dir(), "PeppermintExtract");
$temp_file = fopen($temp_filename, "wb+");
if($temp_file === false) {
http_response_code(503);
exit(page_renderer::render_minimal("Unpacking error - $settings->sitename", "<p>Oops! $settings->sitename wasn't able to create a new temporary file with <code>tmpfile()</code>. Perhaps your server is mis-configured?</p>"));
exit(page_renderer::render_minimal("Unpacking error - $settings->sitename", "<p>Oops! $settings->sitename wasn't able to create a new temporary file with <code>tempnam()</code>. Perhaps your server is mis-configured?</p>"));
}
$source = fopen(__FILE__, "r");
if($source === false) {
@ -36,17 +37,14 @@ if(!file_exists($paths->extra_data_directory) ||
fseek($source, __COMPILER_HALT_OFFSET__);
stream_copy_to_stream($source, $temp_file);
$temp_filename = stream_get_meta_data($temp_file)["uri"];
fclose($temp_file);
$extractor = new ZipArchive();
$extractor->open($temp_filename);
$extractor->extractTo($paths->extra_data_directory);
$extractor->close();
if(fclose($temp_file) === false) {
http_response_code(503);
exit(page_renderer::render_minimal("Unpacking error - $settings->sitename", "<p>Oops! $settings->sitename wasn't able to close the temporary file that it created with <code>tmpfile()</code>. Perhaps your server is mis-configured?</p>"));
}
unlink($temp_filename);
unset($error_message_help);
}