From 3ac4dc6e435f728eb76533e70ae10293c6b786a9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 22 Apr 2023 07:16:51 +0530 Subject: [PATCH] Avoid div-by-zero in fit_image --- src/calibre/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/calibre/__init__.py b/src/calibre/__init__.py index 638eac538b..4f0337573e 100644 --- a/src/calibre/__init__.py +++ b/src/calibre/__init__.py @@ -345,6 +345,8 @@ def fit_image(width, height, pwidth, pheight): @param pheight: Height of box @return: scaled, new_width, new_height. scaled is True iff new_width and/or new_height is different from width or height. ''' + if height < 1 or width < 1: + return False, int(width), int(height) scaled = height > pheight or width > pwidth if height > pheight: corrf = pheight / float(height)