Skip to content

Replace piexif with custom orientation-only exif reader/writer#1210

Merged
heynemann merged 1 commit intothumbor:masterfrom
kkopachev:exif-orientation-editor
Dec 5, 2019
Merged

Replace piexif with custom orientation-only exif reader/writer#1210
heynemann merged 1 commit intothumbor:masterfrom
kkopachev:exif-orientation-editor

Conversation

@kkopachev
Copy link
Copy Markdown
Member

Fixes #1204
Closes #1209
(please see both for discussions)

Replacing piexif dependency with simple orientation-only reader. It ignores all other exif tags and does not traverse through IFDs other then IFD0 where orientation supposed to be.

@kkopachev kkopachev requested review from heynemann and okor July 17, 2019 06:14
@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage remained the same at ?% when pulling 200fa6e on kkopachev:exif-orientation-editor into 37c3602 on thumbor:master.

1 similar comment
@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage remained the same at ?% when pulling 200fa6e on kkopachev:exif-orientation-editor into 37c3602 on thumbor:master.

@coveralls
Copy link
Copy Markdown

coveralls commented Jul 17, 2019

Coverage Status

Coverage remained the same at ?% when pulling f1d1321 on kkopachev:exif-orientation-editor into 724e283 on thumbor:master.

@kkopachev kkopachev mentioned this pull request Jul 17, 2019
Copy link
Copy Markdown
Member

@okor okor left a comment

Choose a reason for hiding this comment

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

Thank you!

There are couple of "code quality" warnings which would be cool to clean up: https://app.codacy.com/app/scorphus/thumbor/pullRequest?prid=3867912

And I left some comments about making some of the more obscure looking code more clear to future devs.

But it's great!

if data[:6] != EXIF_HEADER:
raise SyntaxError("not a TIFF file (header %r not valid)" % data[:4])

self.fp = BytesIO(data[6:])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is fp?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

File pointer.
Struggling to find better name. Any suggestions?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Well, since ... I think ... what you are doing here is declaring a named, binary buffer for data[6:] range of bytes ... we might be able to call this exif_buffer?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree with changing the names to more descriptive variables. Great work btw.

raise SyntaxError("not a TIFF file (header %r not valid)" % data[:4])

self.fp = BytesIO(data[6:])
ifh = self.fp.read(8)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What does ifh mean?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It might be helpful to comment why this is only reading out 8 bytes. May be self documenting if ifh had a more descriptive name?

_endian = "<"
_offset = None

def __init__(self, data):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Generally speaking, this __init__ method is quite dense and very difficult to tell what is going on ... at least for a non-pythonist/non-image expert. It may be helpful for future devs to explain what is going on here via comments or even named functions.

@heynemann
Copy link
Copy Markdown
Member

As soon as we get more descriptive names, I think this is good to merge. Thanks @kkopachev!!! Great work!

@kkopachev kkopachev force-pushed the exif-orientation-editor branch from 200fa6e to c9d583a Compare August 12, 2019 02:24
@kkopachev
Copy link
Copy Markdown
Member Author

Thank you for your feedback. Take a look now please.

@cristiandean cristiandean self-requested a review September 15, 2019 22:50
self.exif_buffer.seek(ifd_offset)

for i in range(self._unpack("H", self.exif_buffer.read(2))[0]):
tag, typ, count, data = self._unpack("HHL4s", self.exif_buffer.read(12))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The same here with data variable.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

figured we don't really need all these info, so just unpack tag id.

ifd_offset, = self._unpack("L", header[4:])
self.exif_buffer.seek(ifd_offset)

for i in range(self._unpack("H", self.exif_buffer.read(2))[0]):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since we are not using the i variable, would it be good to change it to _?

What you think?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sure, updated.

@kkopachev kkopachev force-pushed the exif-orientation-editor branch from c9d583a to d1f696b Compare September 16, 2019 16:29
@kkopachev
Copy link
Copy Markdown
Member Author

Any updates here?

@heynemann
Copy link
Copy Markdown
Member

This looks pretty good! Thanks @kkopachev !!!

@heynemann heynemann merged commit 034abe7 into thumbor:master Dec 5, 2019
@kkopachev kkopachev deleted the exif-orientation-editor branch December 5, 2019 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EXIF parsing causing memory explosion

5 participants