From 6a25965ae0daae2f5967d4e5a8455c93dbc14517 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 | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/apps/dav/lib/CardDAV/PhotoCache.php b/apps/dav/lib/CardDAV/PhotoCache.php index 419ef5822d55f..d4fe8128e2649 100644 --- a/apps/dav/lib/CardDAV/PhotoCache.php +++ b/apps/dav/lib/CardDAV/PhotoCache.php @@ -24,8 +24,11 @@ class PhotoCache { private ?IAppData $photoCacheAppData = null; + /** Maximum edge length (in pixels) for photos */ + private const int MAX_SIZE = 2048; + /** @var array */ - public const ALLOWED_CONTENT_TYPES = [ + public const array ALLOWED_CONTENT_TYPES = [ 'image/png' => 'png', 'image/jpeg' => 'jpg', 'image/gif' => 'gif', @@ -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);