X Tutup
Skip to content

Commit d05c3c9

Browse files
committed
fix: max image dimensions are now configurable and have a higher default
1 parent aa498bc commit d05c3c9

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

changelog/unreleased/41175

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
Bugfix: image dimension validation on avatar upload and preview generation
22

33
https://github.com/owncloud/core/pull/41175
4+
https://github.com/owncloud/core/pull/41193

config/config.sample.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,18 @@
10201020
*/
10211021
'preview_max_filesize_image' => 50,
10221022

1023+
/**
1024+
* Define the maximum dimensions of the original image for preview generation
1025+
* In contrary to `preview_max_x` and `preview_max_x` which define the maximum
1026+
* dimensions of generated previews, this setting limits the original images size.
1027+
*
1028+
* Original images being bigger than the defined dimension will not be processed.
1029+
*
1030+
* Value represents the maximum dimension in den format width x height
1031+
* Default is 6016x4000.
1032+
*/
1033+
'preview_max_dimensions' => '6016x4000',
1034+
10231035
/**
10241036
* Define the custom path for the LibreOffice / OpenOffice binary
10251037
*/

lib/private/Preview/Image.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ public function getThumbnail(File $file, $maxX, $maxY, $scalingUp) {
4646
$handle = $file->fopen('r');
4747
$image->load($handle);
4848
$image->fixOrientation();
49-
// don't generate previews on images with too big dimensions
50-
// 4k - 4096×2160
51-
if ($image->width() > 4096 || $image->height() > 2160) {
49+
if (!$this->validateImageDimensions($image)) {
5250
return false;
5351
}
5452

@@ -70,4 +68,24 @@ public function getThumbnail(File $file, $maxX, $maxY, $scalingUp) {
7068
public function isAvailable(FileInfo $file) {
7169
return true;
7270
}
71+
72+
private function validateImageDimensions(\OC_Image $image): bool {
73+
[$width, $height] = $this->getMaxDimensions();
74+
return !($image->width() > $width || $image->height() > $height);
75+
}
76+
77+
private function getMaxDimensions(): array {
78+
// 24 MP - 6016 x 4000
79+
$maxDimension = \OC::$server->getConfig()->getSystemValue('preview_max_dimensions', '6016x4000');
80+
$exploded = explode('x', strtolower($maxDimension));
81+
if ($exploded === false || \count($exploded) !== 2) {
82+
return [6016, 4000];
83+
}
84+
[$w, $h] = $exploded;
85+
if (is_numeric($w) && is_numeric($h)) {
86+
return [(int)$w, (int)$h];
87+
}
88+
89+
return [6016, 4000];
90+
}
7391
}

0 commit comments

Comments
 (0)
X Tutup