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


None yet
2 participants
Copy link

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.


This comment has been minimized.

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.


This comment has been minimized.

Copy link

saimn commented Dec 17, 2018

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


This comment has been minimized.

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.


This comment has been minimized.

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

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)

This comment has been minimized.


saimn Dec 18, 2018


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

This comment has been minimized.


tudacs Dec 18, 2018

Author Contributor

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

tudacs added some commits Dec 18, 2018

Shortens try/sxcept block to keep code cleaner
... and adds a comment where the SyntaxError may come from.

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

1 of 3 checks passed

codecov/patch 75% of diff hit (target 87.47%)
codecov/project 87.37% (-0.1%) compared to 1c0b8d9
continuous-integration/travis-ci/pr The Travis CI build passed

This comment has been minimized.

Copy link

saimn commented Dec 18, 2018

Thanks @tudacs !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment