Skip to content

Commit 1d927d4

Browse files
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 80d20b9) Co-authored-by: Zackery Spytz <[email protected]>
1 parent bab4fe3 commit 1d927d4

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
@@ -1511,6 +1511,7 @@ Nicholas Spies
15111511
Per Spilling
15121512
Joshua Spoerri
15131513
Noah Spurrier
1514+
Zackery Spytz
15141515
Nathan Srebro
15151516
RajGopal Srinivasan
15161517
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)