Skip to content

Commit 2b9726e

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 6ae87ca commit 2b9726e

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
@@ -263,6 +263,14 @@ def test_read_no_comm_chunk(self):
263263
b = io.BytesIO(b'FORM' + struct.pack('>L', 4) + b'AIFF')
264264
self.assertRaises(aifc.Error, aifc.open, b)
265265

266+
def test_read_no_ssnd_chunk(self):
267+
b = b'FORM' + struct.pack('>L', 4) + b'AIFC'
268+
b += b'COMM' + struct.pack('>LhlhhLL', 38, 0, 0, 0, 0, 0, 0)
269+
b += b'NONE' + struct.pack('B', 14) + b'not compressed' + b'\x00'
270+
with self.assertRaisesRegex(aifc.Error, 'COMM chunk and/or SSND chunk'
271+
' missing'):
272+
aifc.open(io.BytesIO(b))
273+
266274
def test_read_wrong_compression_type(self):
267275
b = b'FORM' + struct.pack('>L', 4) + b'AIFC'
268276
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
@@ -1478,6 +1478,7 @@ Nicholas Spies
14781478
Per Spilling
14791479
Joshua Spoerri
14801480
Noah Spurrier
1481+
Zackery Spytz
14811482
Nathan Srebro
14821483
RajGopal Srinivasan
14831484
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)