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

Fixes sigal aborting if image contains malformed metadata #355

merged 4 commits into from
Dec 18, 2018


Copy link

@tudacs tudacs commented Dec 17, 2018

Currently sigal (or better: Whatever reads the metadata) stops working if it encounters malformed Metadata in a picture. This fix prevents the metadata-reading functions from issueing fatal errors by catching the error, returning empty iptc-data and logging the affected file to the output.

Copy link

codecov bot commented Dec 17, 2018

Codecov Report

Merging #355 into master will decrease coverage by 0.09%.
The diff coverage is 75%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #355     +/-   ##
- Coverage   87.47%   87.37%   -0.1%     
  Files          19       19             
  Lines        1429     1434      +5     
+ Hits         1250     1253      +3     
- Misses        179      181      +2
Impacted Files Coverage Δ
sigal/ 91.09% <75%> (-0.84%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1c0b8d9...a65a3de. Read the comment docs.

Copy link

saimn commented Dec 17, 2018

Do you have an example of the traceback raised without this ? I'm surprised by the SyntaxError.

Copy link
Contributor Author

tudacs commented Dec 18, 2018

That's the setup:

 $ pip list
Package    Version
---------- -------
blinker    1.4
Click      7.0
Jinja2     2.10
Markdown   3.0.1
MarkupSafe 1.1.0
pilkit     2.0
Pillow     5.3.0
pip        18.1
setuptools 40.6.3
sigal      1.4.1
wheel      0.32.3

... and the Traceback:

$ sigal build
Collecting albums -Traceback (most recent call last):
  File "sigal/bin/sigal", line 11, in <module>
  File "sigal/local/lib/python2.7/site-packages/click/", line 764, in __call__
    return self.main(*args, **kwargs)
  File "sigal/local/lib/python2.7/site-packages/click/", line 717, in main
    rv = self.invoke(ctx)
  File "sigal/local/lib/python2.7/site-packages/click/", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "sigal/local/lib/python2.7/site-packages/click/", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "sigal/local/lib/python2.7/site-packages/click/", line 555, in invoke
    return callback(*args, **kwargs)
  File "sigal/local/lib/python2.7/site-packages/sigal/", line 141, in build
    gal = Gallery(settings, ncpu=ncpu)
  File "sigal/local/lib/python2.7/site-packages/sigal/", line 582, in __init__
    album = Album(relpath, settings, dirs, files, self)
  File "sigal/local/lib/python2.7/site-packages/sigal/", line 277, in __init__
    media = Image(f, self.path, settings)
  File "sigal/local/lib/python2.7/site-packages/sigal/", line 86, in __init__
  File "sigal/local/lib/python2.7/site-packages/sigal/", line 178, in _get_metadata
    iptc_data = get_iptc_data(self.src_path)
  File "sigal/local/lib/python2.7/site-packages/sigal/", line 247, in get_iptc_data
    raw_iptc = IptcImagePlugin.getiptcinfo(img)
  File "sigal/local/lib/python2.7/site-packages/PIL/", line 251, in getiptcinfo
  File "sigal/local/lib/python2.7/site-packages/PIL/", line 91, in _open
    tag, size = self.field()
  File "sigal/local/lib/python2.7/site-packages/PIL/", line 71, in field
    raise SyntaxError("invalid IPTC/NAA file")
SyntaxError: invalid IPTC/NAA file


I have shortened the paths a bit to just show the part inside the virtualenv. The image causing PIL to fail is not mentioned.

Copy link

saimn commented Dec 18, 2018

Ok thanks, SyntaxError should not be used for this, could you add a comment in the except to explain where it comes from ? With a link to

sigal/ Outdated
if raw_iptc and (2, 120) in raw_iptc:
iptc_data["description"] = raw_iptc[(2, 120)].decode('utf-8')
except SyntaxError:
print("IPTC Error in %s\n"%filename)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use logging instead of a print (see below in the file for examples).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the hint! :) (and/or sorry for not looking for coding standards in sigal first...)

@saimn saimn merged commit 714eeae into saimn:master Dec 18, 2018
Copy link

saimn commented Dec 18, 2018

Thanks @tudacs !

kontza pushed a commit to kontza/sigal that referenced this pull request Aug 28, 2020
Fixes sigal aborting if image contains malformed metadata
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

2 participants