Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ jobs:
cache: poetry

- name: Install dependencies
run: poetry install --only=lint
run: poetry install

- name: Type check code
uses: liskin/gh-problem-matcher-wrap@v3
Expand Down
5 changes: 5 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Changelog
Upcoming
--------

- Raise ``FileTypeError`` for WAV files containing non-PCM audio streams 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.
8 changes: 8 additions & 0 deletions test/test_mediafile_edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import unittest

import mutagen.id3
import pytest

import mediafile
from test import _common
Expand Down Expand Up @@ -173,6 +174,13 @@ def test_broken_symlink(self):
finally:
os.unlink(fn)

def test_mpeglayer3_wav_raises_filetypeerror(self):
# WAV files with WAVE_FORMAT_MPEGLAYER3 (0x0055) contain a MP3 stream
# and cannot be tagged correctly
fn = os.path.join(_common.RSRC, b"mpeglayer3.wav")
with pytest.raises(mediafile.FileTypeError):
mediafile.MediaFile(fn)


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