Skip to content

Commit

Permalink
aiff: fixed IFFChunk.write writing padding at wrong position
Browse files Browse the repository at this point in the history
  • Loading branch information
phw committed Oct 23, 2019
1 parent ce8cb75 commit f4d3c40
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion mutagen/aiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def write(self, data):
# Write the padding bytes
padding = self.padding()
if padding:
self._fileobj.seek(self.data_offset + self.data_size + 1)
self._fileobj.seek(self.data_offset + self.data_size)
self._fileobj.write(b'\x00' * padding)

def delete(self):
Expand Down
28 changes: 22 additions & 6 deletions tests/test_aiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,28 @@ def test_insert_chunk(self):
self.failUnlessEqual(new_iff[u'ID3'].data_size, 0)

def test_insert_padded_chunks(self):
self.iff_2_tmp.insert_chunk(u'TST1')
self.iff_2_tmp[u'TST1'].resize(3)
self.failUnlessEqual(1, self.iff_2_tmp[u'TST1'].padding())
self.iff_2_tmp.insert_chunk(u'TST2')
self.iff_2_tmp[u'TST2'].resize(4)
self.failUnlessEqual(0, self.iff_2_tmp[u'TST2'].padding())
padded = self.iff_2_tmp.insert_chunk(u'TST1')
unpadded = self.iff_2_tmp.insert_chunk(u'TST2')
# The second chunk needs no padding
unpadded.resize(4)
self.failUnlessEqual(4, unpadded.data_size)
self.failUnlessEqual(0, unpadded.padding())
self.failUnlessEqual(12, unpadded.size)
# Resize the first chunk so it needs padding
padded.resize(3)
self.failUnlessEqual(3, padded.data_size)
self.failUnlessEqual(1, padded.padding())
self.failUnlessEqual(12, padded.size)
self.failUnlessEqual(padded.offset + padded.size, unpadded.offset)
# Verify the padding byte gets written correctly
self.file_2_tmp.seek(padded.data_offset)
self.file_2_tmp.write(b'ABCD')
padded.write(b'ABC')
self.file_2_tmp.seek(padded.data_offset)
self.failUnlessEqual(b'ABC\x00', self.file_2_tmp.read(4))
# Verify the second chunk got not overwritten
self.file_2_tmp.seek(unpadded.offset)
self.failUnlessEqual(b'TST2', self.file_2_tmp.read(4))

def test_delete_padded_chunks(self):
iff_file = self.iff_2_tmp
Expand Down

0 comments on commit f4d3c40

Please sign in to comment.