Skip to content

wave.open raises EOFError instead of wave.Error for a truncated fmt chunk #153692

Description

@tonghuaroot

Bug description

wave.open(f, 'rb') is documented to raise wave.Error when a file violates
the WAV format, but it leaks a raw EOFError when the fmt chunk is truncated
(the chunk header declares 16 bytes but fewer are present):

>>> import io, struct, wave
>>> b = b'RIFF' + struct.pack('<L', 24) + b'WAVE' + b'fmt ' + struct.pack('<L', 16) + struct.pack('<HHLLH', 1, 1, 11025, 11025, 1)
>>> wave.open(io.BytesIO(b))
Traceback (most recent call last):
  ...
EOFError

Expected: wave.Error. Wave_read._read_fmt_chunk() raises EOFError on a
short read, but Wave_read.initfp() does not wrap that call, so it escapes the
public API. Every other malformed-input path in the module raises wave.Error.

CPython versions tested on

3.13, 3.14, 3.15

Operating systems tested on

Linux, macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions