Skip to content

Commit d5d1f85

Browse files
committed
Add permission check
1 parent 2f0d75b commit d5d1f85

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

wcfsetup/install/files/lib/data/attachment/Attachment.class.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use wcf\data\ILinkableObject;
77
use wcf\data\IThumbnailFile;
88
use wcf\data\file\File;
9+
use wcf\data\file\thumbnail\FileThumbnail;
910
use wcf\data\file\thumbnail\FileThumbnailList;
1011
use wcf\data\object\type\ObjectTypeCache;
1112
use wcf\system\file\processor\IImageDataProvider;
@@ -492,6 +493,39 @@ public function getImageData(?int $minWidth = null, ?int $minHeight = null): ?Im
492493
return null;
493494
}
494495

495-
return $this->getFile()->getImageData($minWidth, $minHeight);
496+
if (!$this->getFile()->isImage()) {
497+
return null;
498+
}
499+
500+
if ($minWidth !== null || $minHeight !== null) {
501+
if ($this->canViewPreview()) {
502+
$thumbnails = $this->getFile()->getThumbnails();
503+
usort($thumbnails, fn(FileThumbnail $a, FileThumbnail $b) => $a->width <=> $b->width);
504+
505+
foreach ($thumbnails as $thumbnail) {
506+
if ($minWidth !== null && $minWidth > $thumbnail->width) {
507+
continue;
508+
}
509+
if ($minHeight !== null && $minHeight > $thumbnail->height) {
510+
continue;
511+
}
512+
513+
return new ImageData($thumbnail->getLink(), $thumbnail->width, $thumbnail->height);
514+
}
515+
}
516+
517+
if ($minWidth !== null && $minWidth > $this->width) {
518+
return null;
519+
}
520+
if ($minHeight !== null && $minHeight > $this->height) {
521+
return null;
522+
}
523+
}
524+
525+
if (!$this->canDownload()) {
526+
return null;
527+
}
528+
529+
return new ImageData($this->getLink(), $this->width, $this->height);
496530
}
497531
}

wcfsetup/install/files/lib/data/file/File.class.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,12 @@ public function getImageData(?int $minWidth = null, ?int $minHeight = null): ?Im
265265
return new ImageData($thumbnail->getLink(), $thumbnail->width, $thumbnail->height);
266266
}
267267

268-
return null;
268+
if ($minWidth !== null && $minWidth > $this->width) {
269+
return null;
270+
}
271+
if ($minHeight !== null && $minHeight > $this->height) {
272+
return null;
273+
}
269274
}
270275

271276
return new ImageData($this->getLink(), $this->width, $this->height);

wcfsetup/install/files/lib/data/media/Media.class.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,10 @@ public function getImageData(?int $minWidth = null, ?int $minHeight = null): ?Im
320320
return null;
321321
}
322322

323+
if (!$this->isAccessible()) {
324+
return null;
325+
}
326+
323327
if ($minWidth !== null || $minHeight !== null) {
324328
foreach (\array_keys(self::$thumbnailSizes) as $size) {
325329
if ($minWidth !== null && $minWidth > $this->getThumbnailWidth($size)) {
@@ -332,7 +336,12 @@ public function getImageData(?int $minWidth = null, ?int $minHeight = null): ?Im
332336
return new ImageData($this->getThumbnailLink($size), $this->getThumbnailWidth($size), $this->getThumbnailHeight($size));
333337
}
334338

335-
return null;
339+
if ($minWidth !== null && $minWidth > $this->width) {
340+
return null;
341+
}
342+
if ($minHeight !== null && $minHeight > $this->height) {
343+
return null;
344+
}
336345
}
337346

338347
return new ImageData($this->getLink(), $this->width, $this->height);

0 commit comments

Comments
 (0)