From 40780cc1ccb03cde45bfe30a0996af65d9f0d8f8 Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Thu, 9 Jul 2026 20:54:27 +0200 Subject: [PATCH] fix: Cap the photocache size Assisted-by: ClaudeCode:claude-opus-4-8 Signed-off-by: Daniel Kesselberg --- apps/dav/lib/CardDAV/PhotoCache.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/apps/dav/lib/CardDAV/PhotoCache.php b/apps/dav/lib/CardDAV/PhotoCache.php index 419ef5822d55f..503a433a49aea 100644 --- a/apps/dav/lib/CardDAV/PhotoCache.php +++ b/apps/dav/lib/CardDAV/PhotoCache.php @@ -24,6 +24,9 @@ class PhotoCache { private ?IAppData $photoCacheAppData = null; + /** Maximum edge length (in pixels) for photos */ + private const MAX_SIZE = 2048; + /** @var array */ public const ALLOWED_CONTENT_TYPES = [ 'image/png' => 'png', @@ -98,6 +101,9 @@ private function hasPhoto(ISimpleFolder $folder): bool { private function getFile(ISimpleFolder $folder, $size): ISimpleFile { $ext = $this->getExtension($folder); + // cap the size + $size = (int)min($size, self::MAX_SIZE); + if ($size === -1) { $path = 'photo.' . $ext; } else { @@ -122,9 +128,10 @@ private function getFile(ISimpleFolder $folder, $size): ISimpleFile { } $size = (int)($size * $ratio); - if ($size !== -1) { - $photo->resize($size); - } + // cap the size + $size = min($size, self::MAX_SIZE); + + $photo->resize($size); try { $file = $folder->newFile($path);