Skip to content

Commit b852d8c

Browse files
miss-islingtonZackerySpytz
authored andcommitted
[2.7] bpo-31848: Fix broken error handling in Aifc_read.initfp() when the SSND chunk is not found (GH-5240) (GH-5781)
Initialize self._ssnd_chunk so that aifc.Error is raised as intended, not AttributeError. (cherry picked from commit 80d20b9) Co-authored-by: Zackery Spytz <[email protected]>
1 parent 6c7edba commit b852d8c

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

Lib/aifc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ def initfp(self, file):
308308
else:
309309
raise Error, 'not an AIFF or AIFF-C file'
310310
self._comm_chunk_read = 0
311+
self._ssnd_chunk = None
311312
while 1:
312313
self._ssnd_seek_needed = 1
313314
try:

Lib/test/test_aifc.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,14 @@ def test_read_no_comm_chunk(self):
214214
b = io.BytesIO('FORM' + struct.pack('>L', 4) + 'AIFF')
215215
self.assertRaises(aifc.Error, aifc.open, b)
216216

217+
def test_read_no_ssnd_chunk(self):
218+
b = b'FORM' + struct.pack('>L', 4) + b'AIFC'
219+
b += b'COMM' + struct.pack('>LhlhhLL', 38, 0, 0, 0, 0, 0, 0)
220+
b += b'NONE' + struct.pack('B', 14) + b'not compressed' + b'\x00'
221+
with self.assertRaisesRegexp(aifc.Error, 'COMM chunk and/or SSND chunk'
222+
' missing'):
223+
aifc.open(io.BytesIO(b))
224+
217225
def test_read_wrong_compression_type(self):
218226
b = 'FORM' + struct.pack('>L', 4) + 'AIFC'
219227
b += 'COMM' + struct.pack('>LhlhhLL', 23, 0, 0, 0, 0, 0, 0)

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,6 +1345,7 @@ Nicholas Spies
13451345
Per Spilling
13461346
Joshua Spoerri
13471347
Noah Spurrier
1348+
Zackery Spytz
13481349
Nathan Srebro
13491350
RajGopal Srinivasan
13501351
Tage Stabell-Kulo
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix the error handling in Aifc_read.initfp() when the SSND chunk is not found.
2+
Patch by Zackery Spytz.

0 commit comments

Comments
 (0)