Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhail-iurkov committed Jan 20, 2022
1 parent 2aada99 commit 7941276
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 5 additions & 1 deletion piexif/_exif.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ class TYPES:
}


TYPE_LENGTH = {t: calcsize('=' + f) for t, f in TYPE_FORMAT.items() if f}
TYPE_LENGTH = {
t: calcsize('=' + f)
for t, f in TYPE_FORMAT.items()
if f
}


SIMPLE_NUMERICS = [
Expand Down
9 changes: 4 additions & 5 deletions piexif/_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,8 @@ def get_ifd_dict(self, pointer, ifd_name, read_unknown=False):
def _read_tag(self, pointer):
tag, value_type, value_num = self._unpack_from("HHL", pointer)
# Treat unknown types as `Undefined`
value_length = TYPE_LENGTH.get(value_type, 1)
value_length_total = value_length * value_num
if value_length_total > 4:
value_length = TYPE_LENGTH.get(value_type, 1) * value_num
if value_length > 4:
data_pointer = self._unpack_from("L", pointer + 8)[0]
else:
data_pointer = pointer + 8
Expand All @@ -130,8 +129,8 @@ def _read_tag(self, pointer):
# Ascii, Undefined and unknown types
if value_type == TYPES.Ascii:
# Crop ending zero
value_length_total = max(0, value_length_total - 1)
raw_value = self.tiftag[data_pointer:data_pointer+value_length_total]
value_length = max(0, value_length - 1)
raw_value = self.tiftag[data_pointer:data_pointer+value_length]
values = (raw_value, )
else:
# Unpacked types
Expand Down

0 comments on commit 7941276

Please sign in to comment.