diff --git a/piexif/_exif.py b/piexif/_exif.py index a34cb86..fc0200d 100644 --- a/piexif/_exif.py +++ b/piexif/_exif.py @@ -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 = [ diff --git a/piexif/_load.py b/piexif/_load.py index 50bf5a6..9e2d047 100644 --- a/piexif/_load.py +++ b/piexif/_load.py @@ -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 @@ -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