]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix: Max file size for metadata generation 42800/head
authorGit'Fellow <12234510+solracsf@users.noreply.github.com>
Mon, 15 Jan 2024 13:41:36 +0000 (14:41 +0100)
committerRichard Steinmetz <richard@steinmetz.cloud>
Mon, 5 Aug 2024 06:48:15 +0000 (08:48 +0200)
Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
Co-Authored-By: Louis <louis@chmn.me>
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
config/config.sample.php
core/BackgroundJobs/GenerateMetadataJob.php

index 8b3c9feae45b7ee47dd1641e79cae5be2476b87c..f2d06d9acea9202986f0a1758fea00afe42c7824 100644 (file)
@@ -1373,6 +1373,15 @@ $CONFIG = [
        'OC\Preview\XBitmap',
 ],
 
+/**
+ * Maximum file size for metadata generation.
+ * If a file exceeds this size, metadata generation will be skipped.
+ * Note: memory equivalent to this size will be used for metadata generation.
+ *
+ * Default: 256 megabytes.
+ */
+'metadata_max_filesize' => 256,
+
 /**
  * LDAP
  *
index 809e139e6ef0fd1e0bb352f122c46005fa321c5d..c40a1b11f069aa393d012f91a126c251885fe081 100644 (file)
@@ -16,12 +16,17 @@ use OCP\Files\IRootFolder;
 use OCP\FilesMetadata\Exceptions\FilesMetadataNotFoundException;
 use OCP\FilesMetadata\IFilesMetadataManager;
 use OCP\IAppConfig;
+use OCP\IConfig;
 use OCP\IUserManager;
 use Psr\Log\LoggerInterface;
 
 class GenerateMetadataJob extends TimedJob {
+       // Default file size limit for metadata generation (MBytes).
+       protected const DEFAULT_MAX_FILESIZE = 256;
+
        public function __construct(
                ITimeFactory $time,
+               private IConfig $config,
                private IAppConfig $appConfig,
                private IRootFolder $rootFolder,
                private IUserManager $userManager,
@@ -88,6 +93,15 @@ class GenerateMetadataJob extends TimedJob {
                                continue;
                        }
 
+                       // Don't generate metadata for files bigger than configured metadata_max_filesize
+                       // Files are loaded in memory so very big files can lead to an OOM on the server
+                       $nodeSize = $node->getSize();
+                       $nodeLimit = $this->config->getSystemValueInt('metadata_max_filesize', self::DEFAULT_MAX_FILESIZE);
+                       if ($nodeSize > $nodeLimit * 1000000) {
+                               $this->logger->debug("Skipping generating metadata for fileid " . $node->getId() . " as its size exceeds configured 'metadata_max_filesize'.");
+                               continue;
+                       }
+
                        try {
                                $this->filesMetadataManager->getMetadata($node->getId(), false);
                        } catch (FilesMetadataNotFoundException) {