From 2f110265ff4a1dc429d58e7401d68968e42b6db1 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 23 Nov 2020 09:38:28 -0800 Subject: ImageSize: default to DPI 72 if the format specifies DPI of 0. This shouldn't happen, in general, but it can happen with JPEGs that don't conform to the spec. Having a DPI of 0 will blow up size calculations (division by 0). Closes #6880. --- src/Text/Pandoc/ImageSize.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Text/Pandoc/ImageSize.hs b/src/Text/Pandoc/ImageSize.hs index edd88a71e..fc9e1854b 100644 --- a/src/Text/Pandoc/ImageSize.hs +++ b/src/Text/Pandoc/ImageSize.hs @@ -120,7 +120,7 @@ findSvgTag :: ByteString -> Bool findSvgTag img = " ByteString -> Either T.Text ImageSize -imageSize opts img = +imageSize opts img = checkDpi <$> case imageType img of Just Png -> mbToEither "could not determine PNG size" $ pngSize img Just Gif -> mbToEither "could not determine GIF size" $ gifSize img @@ -132,6 +132,12 @@ imageSize opts img = Nothing -> Left "could not determine image type" where mbToEither msg Nothing = Left msg mbToEither _ (Just x) = Right x + -- see #6880, some defective JPEGs may encode dpi 0, so default to 72 + -- if that value is 0 + checkDpi size = + size{ dpiX = if dpiX size == 0 then 72 else dpiX size + , dpiY = if dpiY size == 0 then 72 else dpiY size } + defaultSize :: (Integer, Integer) defaultSize = (72, 72) -- cgit v1.2.3