diff options
author | John MacFarlane <jgm@berkeley.edu> | 2020-11-23 09:38:28 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2020-11-23 09:39:48 -0800 |
commit | 2f110265ff4a1dc429d58e7401d68968e42b6db1 (patch) | |
tree | f5f1522217d988d388983ba9d4f35d50c8b42ec2 /src | |
parent | f7d80b41709ad79729226243e82a166a236934b8 (diff) | |
download | pandoc-2f110265ff4a1dc429d58e7401d68968e42b6db1.tar.gz |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/ImageSize.hs | 8 |
1 files changed, 7 insertions, 1 deletions
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 = "<svg" `B.isInfixOf` img || "<SVG" `B.isInfixOf` img imageSize :: WriterOptions -> 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) |