Skip to content

Commit

Permalink
id3: don't leak IndexError on invalid encoding fields. (Fixes issue #211
Browse files Browse the repository at this point in the history
)
  • Loading branch information
lazka committed Feb 6, 2015
1 parent bafc12b commit 53d3f3a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions mutagen/id3/_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class EncodingSpec(ByteSpec):
def read(self, frame, data):
enc, data = super(EncodingSpec, self).read(frame, data)
if enc < 16:
if enc > 3:
raise ID3JunkFrameError("invalid encoding")
return enc, data
else:
return 0, chr_(enc) + data
Expand Down
3 changes: 2 additions & 1 deletion tests/test__id3specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from tests import TestCase, add

from mutagen._compat import PY2, PY3, text_type
from mutagen.id3 import BitPaddedInt, unsynch
from mutagen.id3 import BitPaddedInt, unsynch, ID3JunkFrameError


class SpecSanityChecks(TestCase):
Expand All @@ -21,6 +21,7 @@ def test_encodingspec(self):
s = EncodingSpec('name')
self.assertEquals((0, b'abcdefg'), s.read(None, b'abcdefg'))
self.assertEquals((3, b'abcdefg'), s.read(None, b'\x03abcdefg'))
self.assertRaises(ID3JunkFrameError, s.read, None, b'\x04abcdefg')
self.assertEquals(b'\x00', s.write(None, 0))
self.assertRaises(TypeError, s.write, None, b'abc')
self.assertRaises(TypeError, s.write, None, None)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_id3.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def loaded_frame(self, tag):

def test_badencoding(self):
self.assertRaises(
IndexError, Frames["TPE1"].fromData, _24, 0, b"\x09ab")
ID3JunkFrameError, Frames["TPE1"].fromData, _24, 0, b"\x09ab")
self.assertRaises(ValueError, Frames["TPE1"], encoding=9, text="ab")

def test_badsync(self):
Expand Down

0 comments on commit 53d3f3a

Please sign in to comment.