Skip to content
Open
Changes from all commits
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
15 changes: 11 additions & 4 deletions apps/dav/lib/CardDAV/PhotoCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
Expand Down
Loading