@@ -145,47 +145,36 @@ def list_ifd(self) -> list:
145145 def _process_field (self , tag_name , count , field_type , type_length , offset ):
146146 values = []
147147 signed = (field_type in [6 , 8 , 9 , 10 ])
148- # XXX investigate
149- # some entries get too big to handle could be malformed
150- # file or problem with self.s2n
151- if count < 1000 :
152- for _ in range (count ):
153- if field_type in (5 , 10 ):
154- # a ratio
155- value = Ratio (
156- self .s2n (offset , 4 , signed ),
157- self .s2n (offset + 4 , 4 , signed )
158- )
159- elif field_type in (11 , 12 ):
160- # a float or double
161- unpack_format = ''
162- if self .endian == 'I' :
163- unpack_format += '<'
164- else :
165- unpack_format += '>'
166- if field_type == 11 :
167- unpack_format += 'f'
168- else :
169- unpack_format += 'd'
170- self .file_handle .seek (self .offset + offset )
171- byte_str = self .file_handle .read (type_length )
172- try :
173- value = struct .unpack (unpack_format , byte_str )
174- except struct .error :
175- logger .warning ('Possibly corrupted field %s' , tag_name )
176- # -1 means corrupted
177- value = - 1
148+ for _ in range (count ):
149+ if field_type in (5 , 10 ):
150+ # a ratio
151+ value = Ratio (
152+ self .s2n (offset , 4 , signed ),
153+ self .s2n (offset + 4 , 4 , signed )
154+ )
155+ elif field_type in (11 , 12 ):
156+ # a float or double
157+ unpack_format = ''
158+ if self .endian == 'I' :
159+ unpack_format += '<'
178160 else :
179- value = self .s2n (offset , type_length , signed )
180- values .append (value )
181- offset = offset + type_length
182- # The test above causes problems with tags that are
183- # supposed to have long values! Fix up one important case.
184- elif tag_name in ('MakerNote' , makernote .canon .CAMERA_INFO_TAG_NAME ):
185- for _ in range (count ):
161+ unpack_format += '>'
162+ if field_type == 11 :
163+ unpack_format += 'f'
164+ else :
165+ unpack_format += 'd'
166+ self .file_handle .seek (self .offset + offset )
167+ byte_str = self .file_handle .read (type_length )
168+ try :
169+ value = struct .unpack (unpack_format , byte_str )
170+ except struct .error :
171+ logger .warning ('Possibly corrupted field %s' , tag_name )
172+ # -1 means corrupted
173+ value = - 1
174+ else :
186175 value = self .s2n (offset , type_length , signed )
187- values .append (value )
188- offset = offset + type_length
176+ values .append (value )
177+ offset = offset + type_length
189178 return values
190179
191180 def _process_field2 (self , ifd_name , tag_name , count , offset ):
@@ -214,6 +203,15 @@ def _process_field2(self, ifd_name, tag_name, count, offset):
214203 values = ''
215204 return values
216205
206+ def _process_field7 (self , ifd_name , tag_name , count , offset ):
207+ # undefined types e.g. MakerNote/UserComment
208+ values = []
209+ for _ in range (count ):
210+ value = self .s2n (offset , 1 , signed = False )
211+ values .append (value )
212+ offset += 1
213+ return values
214+
217215 def _process_tag (self , ifd , ifd_name : str , tag_entry , entry , tag : int , tag_name , relative , stop_tag ) -> None :
218216 field_type = self .s2n (entry + 2 , 2 )
219217
@@ -248,9 +246,11 @@ def _process_tag(self, ifd, ifd_name: str, tag_entry, entry, tag: int, tag_name,
248246
249247 field_offset = offset
250248 values = None
251- if field_type == 2 :
249+ if field_type == 2 : # ascii strings
252250 values = self ._process_field2 (ifd_name , tag_name , count , offset )
253- else :
251+ elif field_type == 7 : # undefined
252+ values = self ._process_field7 (ifd_name , tag_name , count , offset )
253+ else : # numbers
254254 values = self ._process_field (tag_name , count , field_type , type_length , offset )
255255 # now 'values' is either a string or an array
256256 # TODO: use only one type
0 commit comments