Skip to content

Commit

Permalink
mp3: don't fail on non-ascii lame header version flags
Browse files Browse the repository at this point in the history
See https://issues.oss-fuzz.com/issues/42523736

We could raise there, but we are already returning "?" for unknown
flags down below, so just do the same here.
  • Loading branch information
lazka committed Nov 25, 2024
1 parent 6c6e96f commit 3a29f17
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions mutagen/mp3/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,12 @@ def parse_version(cls, fileobj):
# (I have seen such a file)
if (major, minor) < (3, 90) or (
(major, minor) == (3, 90) and data[-11:-10] == b"("):
flag = data.strip(b"\x00").rstrip().decode("ascii")
return (major, minor), u"%d.%d%s" % (major, minor, flag), False
flag = data.strip(b"\x00").rstrip()
try:
flag_string = flag.decode("ascii")
except UnicodeDecodeError:
flag_string = " (?)"
return (major, minor), u"%d.%d%s" % (major, minor, flag_string), False

if len(data) < 11:
raise LAMEError("Invalid version: too long")
Expand Down
1 change: 1 addition & 0 deletions tests/test_mp3.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ def parse(data):
self.assertEqual(parse(b"LAME3.80 "), (u"3.80", False))
self.assertEqual(parse(b"LAME3.88 (beta)"), (u"3.88 (beta)", False))
self.assertEqual(parse(b"LAME3.90 (alpha)"), (u"3.90 (alpha)", False))
self.assertEqual(parse(b"LAME3.80 (no-ascii-\xff)"), (u"3.80 (?)", False))
self.assertEqual(parse(b"LAME3.90 "), (u"3.90.0+", True))
self.assertEqual(parse(b"LAME3.96a"), (u"3.96 (alpha)", True))
self.assertEqual(parse(b"LAME3.96b"), (u"3.96 (beta)", True))
Expand Down

0 comments on commit 3a29f17

Please sign in to comment.