python / python/cpython

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

未关闭
#153,692 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

stdlib type-bug
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

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
  • gh-153693

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 wave.open 开始,检查 Wave_read.initfp() 和 Wave_read._read_fmt_chunk(),报告将它们确定为相关的入口点。为截断的 fmt 块添加回归检查,并验证格式错误的输入会引发 wave.Error 而不是 EOFError;gh-153693 已经与这项工作关联。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
audio-video-rtc
Issue 类型
缺陷
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
描述清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。