Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZeroDivisionError exception caused by JPEG with incomplete LensInfo #319

Closed
cjmayo opened this issue Feb 9, 2022 · 6 comments
Closed

ZeroDivisionError exception caused by JPEG with incomplete LensInfo #319

cjmayo opened this issue Feb 9, 2022 · 6 comments
Labels
bug crash rinohtype aborts due to an uncaught exception

Comments

@cjmayo
Copy link

cjmayo commented Feb 9, 2022

Steps to reproduce (with exiftool and ImageMagick):
Create index.rst:

.. image:: lensinfo.jpg

Then:

$ magick LOGO: lensinfo.jpg
$ exiftool -exif:resolutionunit=inches -LensInfo="100 100 undef undef" lensinfo.jpg
$ rinoh index.rst
...
  File "/usr/lib/python3.10/site-packages/rinoh/backend/pdf/xobject/jpeg.py", line 228, in _parse_exif_ifd
    result[tag] = get_value(type, count, value_or_offset)
  File "/usr/lib/python3.10/site-packages/rinoh/backend/pdf/xobject/jpeg.py", line 219, in get_value
    value = tuple(num / denom for num, denom in pairs)
  File "/usr/lib/python3.10/site-packages/rinoh/backend/pdf/xobject/jpeg.py", line 219, in <genexpr>
    value = tuple(num / denom for num, denom in pairs)
ZeroDivisionError: division by zero

Catching the exception and returning raw_value seems to work OK for me.

(missing resolutionunit also causes an exception but I haven't seen that one in a real photo)

Please also provide the following information:

  • rinohtype version: rinoh 0.5.3 (2021-06-16)
  • Sphinx version: sphinx-build 4.4.0
  • Python version: Python 3.10.2
  • operating system: Linux
@cjmayo cjmayo added bug crash rinohtype aborts due to an uncaught exception labels Feb 9, 2022
@brechtm
Copy link
Owner

brechtm commented Mar 4, 2022

I'm not able to reproduce this despite your detailed instructions. Both rinohtype 0.5.3 and the current master happily process the JPEG file. I think ImageMagick (7.1.0-2) exiftool (12.30) is not willing to add invalid Lensinfo data to the JPEG:

$ exiftool -exif:resolutionunit=inches -LensInfo="100 100 undef undef" lensinfo.jpg
Warning: Not a floating point number for ExifIFD:LensInfo
    1 image files updated

I assume you bumped into this because you had another JPEG with incomplete lens info? Can you share that image (privately, if needed?

@cjmayo
Copy link
Author

cjmayo commented Mar 4, 2022

@brechtm
Copy link
Owner

brechtm commented Mar 5, 2022

This image causes another error for me:

  ...
  File "/private/tmp/lensinfo/lib/python3.9/site-packages/rinoh/backend/pdf/__init__.py", line 392, in __init__
    self.xobject = Reader(filename_or_file)
  File "/private/tmp/lensinfo/lib/python3.9/site-packages/rinoh/backend/pdf/xobject/jpeg.py", line 51, in __init__
    icc_profile, adobe_color_transform, dpi) = self._get_metadata()
  File "/private/tmp/lensinfo/lib/python3.9/site-packages/rinoh/backend/pdf/xobject/jpeg.py", line 114, in _get_metadata
    result = self._parse_exif_segment(header_length)
  File "/private/tmp/lensinfo/lib/python3.9/site-packages/rinoh/backend/pdf/xobject/jpeg.py", line 182, in _parse_exif_segment
    EXIF_UNITS[ifd_0th.get(EXIF_RESOLUTION_UNIT, 2)])
KeyError: 1

A ResolutionUnit value of 1 is currently not being handled by rinohtype. I'll try to address this.

Temporarily mapping 1 to inches, I do see the error you reported, so I can also look into handling that case. 👍

LensInfo contains information about the lens that captured the image. If the minimum f-stops are unknown, they should be encoded as 0/0.

@brechtm
Copy link
Owner

brechtm commented Mar 6, 2022

I finally figured out why exiftool wasn't working for me. I'm using xon.sh, which handles command line arguments differently. This works:

exiftool -exif:resolutionunit=inches "-LensInfo=100 100 undef undef" lensinfo.jpg

@brechtm brechtm closed this as completed in 28737c4 Mar 6, 2022
@brechtm
Copy link
Owner

brechtm commented Mar 6, 2022

Try installing from the master branch to verify whether the issue is fixed now:

pip install https://github.com/brechtm/rinohtype/archive/refs/heads/master.zip

@cjmayo
Copy link
Author

cjmayo commented Mar 7, 2022

Change in 28737c4 fixes this for me. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug crash rinohtype aborts due to an uncaught exception
Projects
None yet
Development

No branches or pull requests

2 participants