bpo-31848: Fix broken error handling in Aifc_read.initfp() when the SSND chunk is not found (GH-5240)

Initialize self._ssnd_chunk so that aifc.Error is raised as intended,
not AttributeError.
(cherry picked from commit 80d20b918b)

Co-authored-by: Zackery Spytz <zspytz@gmail.com>
This commit is contained in:
Miss Islington (bot) 2018-02-20 14:17:30 -08:00 committed by GitHub
parent 6ae87cae09
commit 2b9726eb64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 0 deletions

View file

@ -322,6 +322,7 @@ class Aifc_read:
else: else:
raise Error('not an AIFF or AIFF-C file') raise Error('not an AIFF or AIFF-C file')
self._comm_chunk_read = 0 self._comm_chunk_read = 0
self._ssnd_chunk = None
while 1: while 1:
self._ssnd_seek_needed = 1 self._ssnd_seek_needed = 1
try: try:

View file

@ -263,6 +263,14 @@ class AIFCLowLevelTest(unittest.TestCase):
b = io.BytesIO(b'FORM' + struct.pack('>L', 4) + b'AIFF') b = io.BytesIO(b'FORM' + struct.pack('>L', 4) + b'AIFF')
self.assertRaises(aifc.Error, aifc.open, b) self.assertRaises(aifc.Error, aifc.open, b)
def test_read_no_ssnd_chunk(self):
b = b'FORM' + struct.pack('>L', 4) + b'AIFC'
b += b'COMM' + struct.pack('>LhlhhLL', 38, 0, 0, 0, 0, 0, 0)
b += b'NONE' + struct.pack('B', 14) + b'not compressed' + b'\x00'
with self.assertRaisesRegex(aifc.Error, 'COMM chunk and/or SSND chunk'
' missing'):
aifc.open(io.BytesIO(b))
def test_read_wrong_compression_type(self): def test_read_wrong_compression_type(self):
b = b'FORM' + struct.pack('>L', 4) + b'AIFC' b = b'FORM' + struct.pack('>L', 4) + b'AIFC'
b += b'COMM' + struct.pack('>LhlhhLL', 23, 0, 0, 0, 0, 0, 0) b += b'COMM' + struct.pack('>LhlhhLL', 23, 0, 0, 0, 0, 0, 0)

View file

@ -1478,6 +1478,7 @@ Nicholas Spies
Per Spilling Per Spilling
Joshua Spoerri Joshua Spoerri
Noah Spurrier Noah Spurrier
Zackery Spytz
Nathan Srebro Nathan Srebro
RajGopal Srinivasan RajGopal Srinivasan
Tage Stabell-Kulo Tage Stabell-Kulo

View file

@ -0,0 +1,2 @@
Fix the error handling in Aifc_read.initfp() when the SSND chunk is not found.
Patch by Zackery Spytz.