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

Fix reading for long MakerNote and UserComment #165

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

Lessica
Copy link

@Lessica Lessica commented Apr 5, 2022

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 inside MakerNote still have problems, which requires further investigation.

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)
Copy link
Author

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.

Copy link
Author

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:
Copy link
Author

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):
Copy link
Author

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.

Copy link

@Lakr233 Lakr233 left a 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")
Copy link
Author

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.

Copy link
Author

Choose a reason for hiding this comment

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

This requires further investigation.

Lessica and others added 3 commits May 3, 2023 01:10
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.

None yet

3 participants