diff options
author | Varun Patil <varunpatil@ucla.edu> | 2024-04-07 19:10:19 -0700 |
---|---|---|
committer | backportbot[bot] <backportbot[bot]@users.noreply.github.com> | 2024-05-15 20:16:43 +0000 |
commit | 312dc5612fab1e610270a97a6c82a92947425228 (patch) | |
tree | 6b0d6002a25e288e6118a718caf9912dd57bcf13 /lib/private/Preview/Bitmap.php | |
parent | 10dfb76f283a360e704839e4eca647806db78411 (diff) | |
download | nextcloud-server-312dc5612fab1e610270a97a6c82a92947425228.tar.gz nextcloud-server-312dc5612fab1e610270a97a6c82a92947425228.zip |
fix(preview): check mime type before processing with Imagick
Signed-off-by: Varun Patil <varunpatil@ucla.edu>
Diffstat (limited to 'lib/private/Preview/Bitmap.php')
-rw-r--r-- | lib/private/Preview/Bitmap.php | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/private/Preview/Bitmap.php b/lib/private/Preview/Bitmap.php index 84c7b4a8968..e0f1dc5fcae 100644 --- a/lib/private/Preview/Bitmap.php +++ b/lib/private/Preview/Bitmap.php @@ -38,6 +38,18 @@ use Psr\Log\LoggerInterface; */ abstract class Bitmap extends ProviderV2 { /** + * List of MIME types that this preview provider is allowed to process. + * + * These should correspond to the MIME types *identified* by Imagemagick + * for files to be processed by this provider. These do / will not + * necessarily need to match the MIME types stored in the database + * (which are identified by IMimeTypeDetector). + * + * @return string Regular expression + */ + abstract protected function getAllowedMimeTypes(): string; + + /** * {@inheritDoc} */ public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage { @@ -86,10 +98,19 @@ abstract class Bitmap extends ProviderV2 { * @param int $maxY * * @return \Imagick + * + * @throws \Exception */ private function getResizedPreview($tmpPath, $maxX, $maxY) { $bp = new Imagick(); + // Validate mime type + $bp->pingImage($tmpPath . '[0]'); + $mimeType = $bp->getImageMimeType(); + if (!preg_match($this->getAllowedMimeTypes(), $mimeType)) { + throw new \Exception('File mime type does not match the preview provider: ' . $mimeType); + } + // Layer 0 contains either the bitmap or a flat representation of all vector layers $bp->readImage($tmpPath . '[0]'); |