diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-03-18 07:55:53 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-18 07:55:53 (GMT) |
commit | 134cb01cda50f02725575808130b05d2d776693f (patch) | |
tree | 25cf0f7f9b0404c2e9c6addc7584a24f63f64ca6 /Lib/wave.py | |
parent | bc300ce205f99acb1ef92c37de06dc76147e073b (diff) | |
download | cpython-134cb01cda50f02725575808130b05d2d776693f.zip cpython-134cb01cda50f02725575808130b05d2d776693f.tar.gz cpython-134cb01cda50f02725575808130b05d2d776693f.tar.bz2 |
bpo-32056: Improve exceptions in aifc, wave and sunau. (GH-5951)
Diffstat (limited to 'Lib/wave.py')
-rw-r--r-- | Lib/wave.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/Lib/wave.py b/Lib/wave.py index cf94d5a..f155879 100644 --- a/Lib/wave.py +++ b/Lib/wave.py @@ -253,12 +253,22 @@ class Wave_read: # def _read_fmt_chunk(self, chunk): - wFormatTag, self._nchannels, self._framerate, dwAvgBytesPerSec, wBlockAlign = struct.unpack_from('<HHLLH', chunk.read(14)) + try: + wFormatTag, self._nchannels, self._framerate, dwAvgBytesPerSec, wBlockAlign = struct.unpack_from('<HHLLH', chunk.read(14)) + except struct.error: + raise EOFError from None if wFormatTag == WAVE_FORMAT_PCM: - sampwidth = struct.unpack_from('<H', chunk.read(2))[0] + try: + sampwidth = struct.unpack_from('<H', chunk.read(2))[0] + except struct.error: + raise EOFError from None self._sampwidth = (sampwidth + 7) // 8 + if not self._sampwidth: + raise Error('bad sample width') else: raise Error('unknown format: %r' % (wFormatTag,)) + if not self._nchannels: + raise Error('bad # of channels') self._framesize = self._nchannels * self._sampwidth self._comptype = 'NONE' self._compname = 'not compressed' |