Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
default the preview_max_memory to a half of the max php memory
Signed-off-by: Simon L <[email protected]>
  • Loading branch information
szaimen committed Dec 21, 2022
commit c5212ed721ca632c804e2abffb2e4c946374739c
4 changes: 2 additions & 2 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -1171,9 +1171,9 @@
* If creating the image would allocate more memory, preview generation will
* be disabled and the default mimetype icon is shown. Set to -1 for no limit.
*
* Defaults to ``128`` megabytes
* Defaults to half of the max PHP memory which is ``256`` megabytes in case of 512 max php memory
*/
'preview_max_memory' => 128,
'preview_max_memory' => 256,

/**
* custom path for LibreOffice/OpenOffice binary
Expand Down
17 changes: 13 additions & 4 deletions lib/private/legacy/OC_Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@
*/
class OC_Image implements \OCP\IImage {

// Default memory limit for images to load (128 MBytes).
protected const DEFAULT_MEMORY_LIMIT = 128;

// Default quality for jpeg images
protected const DEFAULT_JPEG_QUALITY = 80;

Expand Down Expand Up @@ -101,6 +98,18 @@ public function __construct($imageRef = null, \OCP\ILogger $logger = null, \OCP\
}
}

public static function getDefaultMemoryLimit(): int {
static $memoryLimit;
if (!isset($memoryLimit)) {
$memoryInfo = \OC::$server->query(\OC\MemoryInfo::class);
$memoryLimit = $memoryInfo->getMemoryLimit();
if ($memoryLimit > 0) {
$memoryLimit = $memoryLimit / (1024 * 1024 * 2); // getMemoryLimit returns the value in bytes but we need it in megabytes and divide it by 2
}
}
return $memoryLimit;
}

/**
* Determine whether the object contains an image resource.
*
Expand Down Expand Up @@ -577,7 +586,7 @@ public function loadFromFileHandle($handle) {
* @return bool true if allocating is allowed, false otherwise
*/
private function checkImageMemory($width, $height) {
$memory_limit = $this->config->getSystemValueInt('preview_max_memory', self::DEFAULT_MEMORY_LIMIT);
$memory_limit = $this->config->getSystemValueInt('preview_max_memory', self::getDefaultMemoryLimit());
if ($memory_limit < 0) {
// Not limited.
return true;
Expand Down