forked from GNUsocial/gnu-social
[ImageEncoder] Ensure proper memory limits are used when loading images from disk
This commit is contained in:
parent
1c1bef76ef
commit
6a2c3eb711
@ -100,6 +100,8 @@ class ImageEncoder extends Plugin
|
||||
|
||||
public function fileMeta(SplFileInfo &$file, ?string &$mimetype, ?int &$width, ?int &$height): bool
|
||||
{
|
||||
$old_limit = ini_set('memory_limit', Common::config('attachments', 'memory_limit'));
|
||||
try {
|
||||
$original_mimetype = $mimetype;
|
||||
if (GSFile::mimetypeMajor($original_mimetype) !== 'image') {
|
||||
// Nothing concerning us
|
||||
@ -114,7 +116,9 @@ class ImageEncoder extends Plugin
|
||||
}
|
||||
$width = $image->width;
|
||||
$height = $image->height;
|
||||
|
||||
} finally {
|
||||
ini_set('memory_limit', $old_limit); // Restore the old memory limit
|
||||
}
|
||||
// Only one plugin can handle meta
|
||||
return true;
|
||||
}
|
||||
@ -138,6 +142,8 @@ class ImageEncoder extends Plugin
|
||||
*/
|
||||
public function fileSanitize(SplFileInfo &$file, ?string &$mimetype, ?int &$width, ?int &$height): bool
|
||||
{
|
||||
$old_limit = ini_set('memory_limit', Common::config('attachments', 'memory_limit'));
|
||||
try {
|
||||
$original_mimetype = $mimetype;
|
||||
if (GSFile::mimetypeMajor($original_mimetype) !== 'image') {
|
||||
// Nothing concerning us
|
||||
@ -174,6 +180,9 @@ class ImageEncoder extends Plugin
|
||||
|
||||
// Replace original file with the sanitized one
|
||||
$temp->commit($file->getRealPath());
|
||||
} finally {
|
||||
ini_set('memory_limit', $old_limit); // Restore the old memory limit
|
||||
}
|
||||
|
||||
// Only one plugin can handle sanitization
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user