-
Notifications
You must be signed in to change notification settings - Fork 191
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
Fix reading for long MakerNote and UserComment #165
base: develop
Are you sure you want to change the base?
Conversation
exifread/classes.py
Outdated
values = self._process_field2(ifd_name, tag_name, count, offset) | ||
else: | ||
elif field_type == 7: # undefined | ||
values = self._process_field7(ifd_name, tag_name, count, offset) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better not to handle data format 7 (undefined) type in function _process_field
, which is used to parse signed/unsigned numbers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's why I moved this special case into another function _process_field7
.
# XXX investigate | ||
# some entries get too big to handle could be malformed | ||
# file or problem with self.s2n | ||
if count < 1000: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot just ignore large entries other than MakerNote
.
offset = offset + type_length | ||
# The test above causes problems with tags that are | ||
# supposed to have long values! Fix up one important case. | ||
elif tag_name in ('MakerNote', makernote.canon.CAMERA_INFO_TAG_NAME): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to function _process_field7
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -97,6 +97,8 @@ def s2n(self, offset, length: int, signed=False) -> int: | |||
raise ValueError('unexpected unpacking length: %d' % length) from err | |||
self.file_handle.seek(self.offset + offset) | |||
buf = self.file_handle.read(length) | |||
if len(buf) != length: | |||
raise ValueError("cannot read enough bytes, something elsewhere is wrong") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This prevents infinite loop in some tests. But it will not be fixed until the parsing of Canon's MakerNote
being fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This requires further investigation.
Keep raw values for undefined types e.g. `MakerNote` and `UserComment`
05fe609
to
04efa3f
Compare
Top-level large entries (e.g. MakerNote and UserComment) are usually in data format 7 (unspecified). See: http://www.fifi.org/doc/jhead/exif-e.html#DataForm
We should simply ignore its length, read and keep its original values for further use.
But
IfdTag
entries insideMakerNote
still have problems, which requires further investigation.