Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
bits_per_byte = 7 if id3version == 4 else 8 # only id3v2.4 is synchsafe
frame_header_data = fh.read(frame_header_size)
if len(frame_header_data) != frame_header_size:
return 0
frame = struct.unpack(binformat, frame_header_data)
frame_id = self._decode_string(frame[0])
frame_size = self._calc_size(frame[1:1+frame_size_bytes], bits_per_byte)
if DEBUG:
stderr('Found id3 Frame %s at %d-%d of %d' % (frame_id, fh.tell(), fh.tell() + frame_size, self.filesize))
if frame_size > 0:
# flags = frame[1+frame_size_bytes:] # dont care about flags.
if frame_id not in ID3.PARSABLE_FRAME_IDS: # jump over unparsable frames
fh.seek(frame_size, os.SEEK_CUR)
return frame_size
content = fh.read(frame_size)
fieldname = ID3.FRAME_ID_TO_FIELD.get(frame_id)
if fieldname:
transfunc = self._decode_comment if fieldname == 'comment' else self._decode_string
self._set_field(fieldname, content, transfunc)
elif frame_id in self.IMAGE_FRAME_IDS and self._load_image:
# See section 4.14: http://id3.org/id3v2.4.0-frames
if frame_id == 'PIC': # ID3 v2.2:
desc_end_pos = content.index(b'\x00', 1) + 1
else: # ID3 v2.3+
mimetype_end_pos = content.index(b'\x00', 1) + 1
desc_start_pos = mimetype_end_pos + 1 # jump over picture type
desc_end_pos = content.index(b'\x00', desc_start_pos) + 1
if content[desc_end_pos:desc_end_pos+1] == b'\x00':
desc_end_pos += 1 # the description ends with 1 or 2 null bytes
self._image_data = content[desc_end_pos:]
return frame_size
return 0