Skip to content

Commit a775dfe

Browse files
committed
fix: apply max file size limits to class Bitmap
1 parent 87487f4 commit a775dfe

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

lib/private/Preview.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
use OC\Files\Filesystem;
3535
use OC\Files\View;
3636
use OCA\Files_Sharing\SharedMount;
37+
use OCP\Files\File;
3738
use OCP\Files\FileInfo;
3839
use OCP\Files\Folder;
3940
use OCP\Files\Node;
@@ -1081,6 +1082,22 @@ private function getPreviewPath($fileId = null) {
10811082
return $this->getThumbnailsFolder() . '/' . $fileId . '/';
10821083
}
10831084

1085+
/**
1086+
* @param File $file
1087+
* @return bool
1088+
* @throws \OCP\Files\InvalidPathException
1089+
* @throws \OCP\Files\NotFoundException
1090+
*/
1091+
public static function isImageFileSizeTooBig(File $file): bool {
1092+
$maxSizeForImages = \OC::$server->getConfig()->getSystemValue('preview_max_filesize_image', 50);
1093+
if ($maxSizeForImages === -1) {
1094+
return false;
1095+
}
1096+
$size = $file->getSize();
1097+
1098+
return $size > ($maxSizeForImages * 1024 * 1024);
1099+
}
1100+
10841101
/**
10851102
* Asks the provider to send a preview of the file which respects the maximum dimensions
10861103
* defined in the configuration and after saving it in the cache, it is then resized to the

lib/private/Preview/Bitmap.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
namespace OC\Preview;
2626

2727
use Imagick;
28+
use OC\Preview;
2829
use OCP\Files\File;
2930
use OCP\Files\FileInfo;
3031
use OCP\Preview\IProvider2;
@@ -40,6 +41,9 @@ abstract class Bitmap implements IProvider2 {
4041
* {@inheritDoc}
4142
*/
4243
public function getThumbnail(File $file, $maxX, $maxY, $scalingUp) {
44+
if (Preview::isImageFileSizeTooBig($file)) {
45+
return false;
46+
}
4347
$stream = $file->fopen('r');
4448

4549
// Creates \Imagick object from bitmap or vector file
@@ -78,9 +82,9 @@ public function isAvailable(FileInfo $file) {
7882
* @param int $maxX
7983
* @param int $maxY
8084
*
81-
* @return \Imagick
85+
* @return Imagick
8286
*/
83-
private function getResizedPreview($stream, $maxX, $maxY) {
87+
private function getResizedPreview($stream, int $maxX, int $maxY): Imagick {
8488
# file content can be SVG - we need to sanitize it first
8589
$content = \stream_get_contents($stream);
8690
$output = SVG::sanitizeSVGContent($content);

lib/private/Preview/Image.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
*/
2727
namespace OC\Preview;
2828

29+
use OC\Preview;
2930
use OCP\Files\File;
3031
use OCP\Files\FileInfo;
3132
use OCP\Preview\IProvider2;
@@ -35,13 +36,9 @@ abstract class Image implements IProvider2 {
3536
* {@inheritDoc}
3637
*/
3738
public function getThumbnail(File $file, $maxX, $maxY, $scalingUp) {
38-
$maxSizeForImages = \OC::$server->getConfig()->getSystemValue('preview_max_filesize_image', 50);
39-
$size = $file->getSize();
40-
41-
if ($maxSizeForImages !== -1 && $size > ($maxSizeForImages * 1024 * 1024)) {
39+
if (Preview::isImageFileSizeTooBig($file)) {
4240
return false;
4341
}
44-
4542
$image = new \OC_Image();
4643
$handle = $file->fopen('r');
4744
$image->load($handle);

0 commit comments

Comments
 (0)