mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
gh-77171: Fixes SubFormat check to compare the entire value. Add docs (GH-97509)
This commit is contained in:
parent
f1cca801f5
commit
a4ac14faa5
3 changed files with 21 additions and 6 deletions
18
Lib/wave.py
18
Lib/wave.py
|
@ -84,6 +84,8 @@ class Error(Exception):
|
|||
|
||||
WAVE_FORMAT_PCM = 0x0001
|
||||
WAVE_FORMAT_EXTENSIBLE = 0xFFFE
|
||||
# Derived from uuid.UUID("00000001-0000-0010-8000-00aa00389b71").bytes_le
|
||||
KSDATAFORMAT_SUBTYPE_PCM = b'\x01\x00\x00\x00\x00\x00\x10\x00\x80\x00\x00\xaa\x008\x9bq'
|
||||
|
||||
_array_fmts = None, 'b', 'h', None, 'i'
|
||||
|
||||
|
@ -386,12 +388,20 @@ class Wave_read:
|
|||
raise EOFError from None
|
||||
if wFormatTag == WAVE_FORMAT_EXTENSIBLE:
|
||||
try:
|
||||
# Only the first 2 bytes (of 16) of SubFormat are needed.
|
||||
cbSize, wValidBitsPerSample, dwChannelMask, SubFormatFmt = struct.unpack_from('<HHLH', chunk.read(10))
|
||||
cbSize, wValidBitsPerSample, dwChannelMask = struct.unpack_from('<HHL', chunk.read(8))
|
||||
# Read the entire UUID from the chunk
|
||||
SubFormat = chunk.read(16)
|
||||
if len(SubFormat) < 16:
|
||||
raise EOFError
|
||||
except struct.error:
|
||||
raise EOFError from None
|
||||
if SubFormatFmt != WAVE_FORMAT_PCM:
|
||||
raise Error(f'unknown format: {SubFormatFmt}')
|
||||
if SubFormat != KSDATAFORMAT_SUBTYPE_PCM:
|
||||
try:
|
||||
import uuid
|
||||
subformat_msg = f'unknown extended format: {uuid.UUID(bytes_le=SubFormat)}'
|
||||
except Exception:
|
||||
subformat_msg = 'unknown extended format'
|
||||
raise Error(subformat_msg)
|
||||
self._sampwidth = (sampwidth + 7) // 8
|
||||
if not self._sampwidth:
|
||||
raise Error('bad sample width')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue