From e2832ec77b90efacbb29a99e855a29d927515730 Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Thu, 18 Jan 2018 23:42:14 -0700 Subject: [PATCH 1/2] bpo-31848: Fix broken error handling in Aifc_read.initfp() when the SSND chunk is not found Initialize self._ssnd_chunk so that aifc.Error is raised as intended, not AttributeError. --- Lib/aifc.py | 1 + Lib/test/test_aifc.py | 8 ++++++++ .../next/Library/2018-01-18-23-34-17.bpo-31848.M2cldy.rst | 1 + 3 files changed, 10 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2018-01-18-23-34-17.bpo-31848.M2cldy.rst diff --git a/Lib/aifc.py b/Lib/aifc.py index e51e8f8e484095c..3d2dc56de198cd7 100644 --- a/Lib/aifc.py +++ b/Lib/aifc.py @@ -322,6 +322,7 @@ def initfp(self, file): else: raise Error('not an AIFF or AIFF-C file') self._comm_chunk_read = 0 + self._ssnd_chunk = None while 1: self._ssnd_seek_needed = 1 try: diff --git a/Lib/test/test_aifc.py b/Lib/test/test_aifc.py index a064a324705799e..8fd306a36592030 100644 --- a/Lib/test/test_aifc.py +++ b/Lib/test/test_aifc.py @@ -266,6 +266,14 @@ def test_read_no_comm_chunk(self): b = io.BytesIO(b'FORM' + struct.pack('>L', 4) + b'AIFF') 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): b = b'FORM' + struct.pack('>L', 4) + b'AIFC' b += b'COMM' + struct.pack('>LhlhhLL', 23, 0, 0, 0, 0, 0, 0) diff --git a/Misc/NEWS.d/next/Library/2018-01-18-23-34-17.bpo-31848.M2cldy.rst b/Misc/NEWS.d/next/Library/2018-01-18-23-34-17.bpo-31848.M2cldy.rst new file mode 100644 index 000000000000000..3889208b3c7e632 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-01-18-23-34-17.bpo-31848.M2cldy.rst @@ -0,0 +1 @@ +Fix error handling in Aifc_read.initfp() when the SSND chunk is not found. From 453f373ae309b0de1ad60b81a4b2ae3aeefbca7e Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Tue, 20 Feb 2018 03:11:54 -0700 Subject: [PATCH 2/2] Add my name. --- Misc/ACKS | 1 + .../next/Library/2018-01-18-23-34-17.bpo-31848.M2cldy.rst | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Misc/ACKS b/Misc/ACKS index 009b072d680aac6..d39a61891669929 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1505,6 +1505,7 @@ Nicholas Spies Per Spilling Joshua Spoerri Noah Spurrier +Zackery Spytz Nathan Srebro RajGopal Srinivasan Tage Stabell-Kulo diff --git a/Misc/NEWS.d/next/Library/2018-01-18-23-34-17.bpo-31848.M2cldy.rst b/Misc/NEWS.d/next/Library/2018-01-18-23-34-17.bpo-31848.M2cldy.rst index 3889208b3c7e632..c8e61acb0b066b3 100644 --- a/Misc/NEWS.d/next/Library/2018-01-18-23-34-17.bpo-31848.M2cldy.rst +++ b/Misc/NEWS.d/next/Library/2018-01-18-23-34-17.bpo-31848.M2cldy.rst @@ -1 +1,2 @@ -Fix error handling in Aifc_read.initfp() when the SSND chunk is not found. +Fix the error handling in Aifc_read.initfp() when the SSND chunk is not found. +Patch by Zackery Spytz.