Skip to content

Commit 80d20b9

Browse files
ZackerySpytzserhiy-storchaka
authored andcommitted
bpo-31848: Fix broken error handling in Aifc_read.initfp() when the SSND chunk is not found (#5240)
Initialize self._ssnd_chunk so that aifc.Error is raised as intended, not AttributeError.
1 parent 7a1e178 commit 80d20b9

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
@@ -322,6 +322,7 @@ def initfp(self, file):
322322
else:
323323
raise Error('not an AIFF or AIFF-C file')
324324
self._comm_chunk_read = 0
325+
self._ssnd_chunk = None
325326
while 1:
326327
self._ssnd_seek_needed = 1
327328
try:

Lib/test/test_aifc.py

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

269+
def test_read_no_ssnd_chunk(self):
270+
b = b'FORM' + struct.pack('>L', 4) + b'AIFC'
271+
b += b'COMM' + struct.pack('>LhlhhLL', 38, 0, 0, 0, 0, 0, 0)
272+
b += b'NONE' + struct.pack('B', 14) + b'not compressed' + b'\x00'
273+
with self.assertRaisesRegex(aifc.Error, 'COMM chunk and/or SSND chunk'
274+
' missing'):
275+
aifc.open(io.BytesIO(b))
276+
269277
def test_read_wrong_compression_type(self):
270278
b = b'FORM' + struct.pack('>L', 4) + b'AIFC'
271279
b += 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
@@ -1512,6 +1512,7 @@ Nicholas Spies
15121512
Per Spilling
15131513
Joshua Spoerri
15141514
Noah Spurrier
1515+
Zackery Spytz
15151516
Nathan Srebro
15161517
RajGopal Srinivasan
15171518
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)