Skip to content

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

Open

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

Activity

  1. added
    type-feature
    stdlib
    type-bug
    and removed
    type-feature
    on Jul 14, 2026
  2. added a commit that references this issue on Jul 14, 2026
  3. serhiy-storchaka commented on Aug 17, 2026

    @serhiy-storchaka
    Member

    This is a deliberate choice rather than an oversight. The EOFError comes from 134cb01 (bpo-32056, GH-5951), which converted struct.error to EOFError for a truncated chunk while raising Error for invalid content in the very same commit (unknown format, bad sample width, bad # of channels). Truncation and malformed contents were separated on purpose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibtype-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions