Skip to content
Open
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
7 changes: 7 additions & 0 deletions Lib/test/test_wave.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,13 @@ def test_read_wrong_sample_width(self):
with self.assertRaisesRegex(wave.Error, 'bad sample width'):
wave.open(io.BytesIO(b))

def test_read_truncated_fmt_chunk(self):
b = b'RIFF' + struct.pack('<L', 24) + b'WAVE'
b += b'fmt ' + struct.pack('<L', 16)
b += struct.pack('<HHLLH', 1, 1, 11025, 11025, 1)
with self.assertRaisesRegex(wave.Error, 'fmt chunk is truncated'):
wave.open(io.BytesIO(b))

def test_open_in_write_raises(self):
# gh-136523: Wave_write.__del__ should not throw
with support.catch_unraisable_exception() as cm:
Expand Down
5 changes: 4 additions & 1 deletion Lib/wave.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,10 @@ def initfp(self, file):
break
chunkname = chunk.getname()
if chunkname == b'fmt ':
self._read_fmt_chunk(chunk)
try:
self._read_fmt_chunk(chunk)
except EOFError:
raise Error('fmt chunk is truncated') from None
self._fmt_chunk_read = 1
elif chunkname == b'data':
if not self._fmt_chunk_read:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:func:`wave.open` now raises :exc:`wave.Error` instead of :exc:`EOFError` when
the ``fmt`` chunk of a WAV file is truncated. Patch by tonghuaroot.
Loading