Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Changelog

Upcoming
--------
- Raise ``FileTypeError`` for WAV files containing non-PCM audio streams
Comment thread
snejus marked this conversation as resolved.
Outdated
that mutagen cannot tag correctly, including ``WAVE_FORMAT_MPEGLAYER3``
(0x0055), ``WAVE_FORMAT_ADPCM`` (0x0002), ``WAVE_FORMAT_ALAW`` (0x0006),
and ``WAVE_FORMAT_MULAW`` (0x0007).

v0.16.0
-------
Expand Down
11 changes: 11 additions & 0 deletions mediafile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,17 @@ def __init__(self, filething, id3v23=False):
elif type(self.mgfile).__name__ == "DSF":
self.type = "dsf"
elif type(self.mgfile).__name__ == "WAVE":
# WAV files can contain non-PCM audio streams that mutagen
# cannot tag correctly. Rejects them with a clear error.
_unsupported_wav_formats = {
0x0002: "WAVE_FORMAT_ADPCM",
0x0006: "WAVE_FORMAT_ALAW",
0x0007: "WAVE_FORMAT_MULAW",
0x0055: "WAVE_FORMAT_MPEGLAYER3",
}
audio_fmt = getattr(self.mgfile.info, "audio_format", 0x0001)
if audio_fmt in _unsupported_wav_formats:
raise FileTypeError(self.filename, _unsupported_wav_formats[audio_fmt])
self.type = "wav"
else:
raise FileTypeError(self.filename, type(self.mgfile).__name__)
Expand Down
Binary file added test/rsrc/mpeglayer3.wav
Binary file not shown.
6 changes: 6 additions & 0 deletions test/test_mediafile_edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ def test_broken_symlink(self):
finally:
os.unlink(fn)

def test_mpeglayer3_wav_raises_filetypeerror(self):
# WAV files with WAVE_FORMAT_MPEGLAYER3 (OxOO55) contain a MP3 stream
Comment thread
elainec2024 marked this conversation as resolved.
Outdated
# and cannot be tagged correctly
fn = os.path.join(_common.RSRC, b"mpeglayer3.wav")
self.assertRaises(mediafile.FileTypeError, mediafile.MediaFile, fn)
Comment thread
snejus marked this conversation as resolved.
Outdated


class SideEffectsTest(unittest.TestCase):
def setUp(self):
Expand Down
Loading