]> granicus.if.org Git - python/commitdiff
[2.7] bpo-31848: Fix broken error handling in Aifc_read.initfp() when the SSND chunk...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 21 Feb 2018 06:37:18 +0000 (22:37 -0800)
committerSerhiy Storchaka <storchaka@gmail.com>
Wed, 21 Feb 2018 06:37:18 +0000 (08:37 +0200)
Initialize self._ssnd_chunk so that aifc.Error is raised as intended,
not AttributeError.
(cherry picked from commit 80d20b918bd8a882043c493a7f958333ecb41727)

Co-authored-by: Zackery Spytz <zspytz@gmail.com>
Lib/aifc.py
Lib/test/test_aifc.py
Misc/ACKS
Misc/NEWS.d/next/Library/2018-01-18-23-34-17.bpo-31848.M2cldy.rst [new file with mode: 0644]

index e6783277a471c1adcb50a3c5515743076c7fc842..981f8010690e00e75f1b4605f456edf41d32527a 100644 (file)
@@ -308,6 +308,7 @@ class Aifc_read:
         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:
index d1b7dd0432579cf84039fb08e68580cb2a0eddc3..92bbe7bc75da93f2648f18fe4ec6ce5cb535ef72 100644 (file)
@@ -214,6 +214,14 @@ class AIFCLowLevelTest(unittest.TestCase):
         b = io.BytesIO('FORM' + struct.pack('>L', 4) + '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.assertRaisesRegexp(aifc.Error, 'COMM chunk and/or SSND chunk'
+                                                 ' missing'):
+            aifc.open(io.BytesIO(b))
+
     def test_read_wrong_compression_type(self):
         b = 'FORM' + struct.pack('>L', 4) + 'AIFC'
         b += 'COMM' + struct.pack('>LhlhhLL', 23, 0, 0, 0, 0, 0, 0)
index f0a115d5d555596ffb4efcfa46cd3b7614fbd0c9..e02060d8dcf1bb0c8c95403012b78ad4b3bc3b14 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1345,6 +1345,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
new file mode 100644 (file)
index 0000000..c8e61ac
--- /dev/null
@@ -0,0 +1,2 @@
+Fix the error handling in Aifc_read.initfp() when the SSND chunk is not found.
+Patch by Zackery Spytz.