Merge pull request #108 from nyanpasu64/ignore_bad_wav_header

Accept invalid .wav with header metadata larger than filesize
pull/357/head
nyanpasu64 2019-01-03 01:00:25 -08:00 zatwierdzone przez GitHub
commit a13ef88e69
3 zmienionych plików z 17 dodań i 1 usunięć

Wyświetl plik

@ -274,7 +274,9 @@ def read(filename, mmap=False):
chunk_id = fid.read(4)
if not chunk_id:
raise ValueError("Unexpected end of file.")
warnings.warn("Wave ends before header's indicated file size",
WavFileWarning)
break
elif len(chunk_id) < 4:
raise ValueError("Incomplete wav chunk.")

Plik binarny nie jest wyświetlany.

Wyświetl plik

@ -5,6 +5,7 @@ from numpy.testing import assert_allclose
import pytest
from delayed_assert import expect, assert_expectations
from corrscope.utils.scipy_wavfile import WavFileWarning
from corrscope.wave import Wave
prefix = 'tests/wav-formats/'
@ -106,3 +107,16 @@ def test_stereo_doesnt_overflow():
expect(np.amax(np.abs(np.diff(data))) < 0.5)
assert_expectations()
def test_header_larger_than_filesize():
"""According to Zeinok, VortexTracker 2.5 produces slightly corrupted WAV files
whose RIFF header metadata indicates a filesize larger than the actual filesize.
Most programs read the audio chunk fine.
Scipy normally rejects such files, raises ValueError("Unexpected end of file.")
My version instead accepts such files (but warns WavFileWarning).
"""
with pytest.warns(WavFileWarning):
wave = Wave(None, 'tests/header larger than filesize.wav')
assert wave