From 0ac80ddf30cf5fdee294df18e69fb632befc47d5 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 23 Mar 2014 17:39:42 +0100 Subject: [PATCH] imagebox: Avoid division by zero Given an imagebox i with i.resize_forbidden = false and a valid image set, the call t:fit(0, 0) would return two times "not a number". This is because the code first does some calculations to get the input image into the available space and then tried to do some calculations needed for scaling images up. The first calculation already gave us h == 0 == w, the second calculation would then calculate 0/0. This results in NaNs. This was only noticed because NaN is not a valid table index in lua. Fix this by returning 0,0 if we have an image of width or height 0 after the first calculation. Since 0x0 images are valid in cairo, this also fixes the same bug with such images. Signed-off-by: Uli Schlachter --- lib/wibox/widget/imagebox.lua.in | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/wibox/widget/imagebox.lua.in b/lib/wibox/widget/imagebox.lua.in index 7aa8b09d6..da5163493 100644 --- a/lib/wibox/widget/imagebox.lua.in +++ b/lib/wibox/widget/imagebox.lua.in @@ -55,6 +55,10 @@ function imagebox:fit(width, height) h = height end + if h == 0 or w == 0 then + return 0, 0 + end + if not self.resize_forbidden then local aspect = width / w local aspect_h = height / h