From f6b73a5150f6a31051ddc67b0276ecdb5ae75761 Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 14 Oct 2019 21:16:04 -0500 Subject: [PATCH] posts: fix exception when rendering thumbnails for posts with null width/height. Fixes https://danbooru.donmai.us/forum_topics/15909?page=4#forum_post_160367. --- app/presenters/post_presenter.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index 8a5c26fec..4efe7b8ba 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -63,9 +63,15 @@ class PostPresenter < Presenter locals[:width] = post.image_width locals[:height] = post.image_height - downscale_ratio = Danbooru.config.small_image_width.to_f / [post.image_width, post.image_height].max - locals[:preview_width] = [(downscale_ratio * post.image_width).floor, post.image_width].min - locals[:preview_height] = [(downscale_ratio * post.image_height).floor, post.image_height].min + # XXX work around ancient bad posts with null or zero dimensions. + if post.image_width.to_i > 0 && post.image_height.to_i > 0 + downscale_ratio = Danbooru.config.small_image_width.to_f / [post.image_width, post.image_height].max + locals[:preview_width] = [(downscale_ratio * post.image_width).floor, post.image_width].min + locals[:preview_height] = [(downscale_ratio * post.image_height).floor, post.image_height].min + else + locals[:preview_width] = 0 + locals[:preview_height] = 0 + end if options[:similarity] locals[:similarity] = options[:similarity].round