Skip to content

Commit

Permalink
Don't segfault on zero-channel MP3s. (#381)
Browse files Browse the repository at this point in the history
* Don't segfault on zero-channel MP3s. Fixes #379.

* Whoops.
  • Loading branch information
psobot authored Nov 6, 2024
1 parent 115d7e3 commit 1273304
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pedalboard/juce_overrides/juce_PatchedMP3AudioFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3323,6 +3323,10 @@ class PatchedMP3Reader : public AudioFormatReaderWithPosition {
return false;
}

if (numDestChannels == 0) {
return true;
}

if (currentPosition != startSampleInFile) {
if (!stream.seek((int)(startSampleInFile / samplesPerFrame - 1))) {
currentPosition = -1;
Expand Down
Binary file added tests/audio/correct/zero_channels.mp3
Binary file not shown.
7 changes: 7 additions & 0 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,13 @@ def test_real_mp3_parsing_with_no_header():
assert f.read(f.frames).shape[1] == f.frames


def test_real_mp3_parsing_with_no_channels():
filename = os.path.join(os.path.dirname(__file__), "audio", "correct", "zero_channels.mp3")
with pedalboard.io.AudioFile(filename) as f:
assert f.num_channels == 0
assert f.read(f.frames).shape == (0, 0)


@pytest.mark.parametrize("samplerate", [44100, 32000])
@pytest.mark.parametrize("chunk_size", [1, 2, 16])
@pytest.mark.parametrize("target_samplerate", [44100, 32000, 22050, 1234.56])
Expand Down

0 comments on commit 1273304

Please sign in to comment.