From 90567772bda8ea52b1a69612477950084a160397 Mon Sep 17 00:00:00 2001 From: Thorsten Date: Sat, 19 Nov 2022 18:16:41 +0100 Subject: [PATCH] Prevent division by zero. --- src/Object/Api/Mastodon/Attachment.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Object/Api/Mastodon/Attachment.php b/src/Object/Api/Mastodon/Attachment.php index 8156155cde..90b1bffb9f 100644 --- a/src/Object/Api/Mastodon/Attachment.php +++ b/src/Object/Api/Mastodon/Attachment.php @@ -63,15 +63,19 @@ class Attachment extends BaseDataTransferObject $this->text_url = $this->remote_url ?? $this->url; $this->description = $attachment['description']; if ($type === 'image') { - $this->meta['original']['width'] = (int) $attachment['width']; - $this->meta['original']['height'] = (int) $attachment['height']; - $this->meta['original']['size'] = (int) $attachment['width'] . 'x' . (int) $attachment['height']; - $this->meta['original']['aspect'] = (float) ((int) $attachment['width'] / (int) $attachment['height']); + if ((int) $attachment['width'] > 0 && (int) $attachment['height'] > 0) { + $this->meta['original']['width'] = (int) $attachment['width']; + $this->meta['original']['height'] = (int) $attachment['height']; + $this->meta['original']['size'] = (int) $attachment['width'] . 'x' . (int) $attachment['height']; + $this->meta['original']['aspect'] = (float) ((int) $attachment['width'] / (int) $attachment['height']); + } - $this->meta['small']['width'] = (int) $attachment['preview-width']; - $this->meta['small']['height'] = (int) $attachment['preview-height']; - $this->meta['small']['size'] = (int) $attachment['preview-width'] . 'x' . (int) $attachment['preview-height']; - $this->meta['small']['aspect'] = (float) ((int) $attachment['preview-width'] / (int) $attachment['preview-height']); + if ((int) $attachment['preview-width'] > 0 && (int) $attachment['preview-height'] > 0) { + $this->meta['small']['width'] = (int) $attachment['preview-width']; + $this->meta['small']['height'] = (int) $attachment['preview-height']; + $this->meta['small']['size'] = (int) $attachment['preview-width'] . 'x' . (int) $attachment['preview-height']; + $this->meta['small']['aspect'] = (float) ((int) $attachment['preview-width'] / (int) $attachment['preview-height']); + } } }