Fix issue 2245. aifc now skips any chunk type it doesn't actually
process instead of throwing errors for anything not in an explicit
skip list. This is per this spec: http://www.cnpbagwell.com/aiff-c.txt.
Spec reference and test sound file provided by Santiago Peresón, fix
based on patch by Hiroaki Kawai.
diff --git a/Lib/aifc.py b/Lib/aifc.py
index f663dd6..8e4f864 100644
--- a/Lib/aifc.py
+++ b/Lib/aifc.py
@@ -144,9 +144,6 @@
_AIFC_version = 0xA2805140L # Version 1 of AIFF-C
-_skiplist = 'COMT', 'INST', 'MIDI', 'AESD', \
- 'APPL', 'NAME', 'AUTH', '(c) ', 'ANNO'
-
def _read_long(file):
try:
return struct.unpack('>l', file.read(4))[0]
@@ -314,10 +311,6 @@
self._version = _read_ulong(chunk)
elif chunkname == 'MARK':
self._readmark(chunk)
- elif chunkname in _skiplist:
- pass
- else:
- raise Error, 'unrecognized chunk type '+chunk.chunkname
chunk.skip()
if not self._comm_chunk_read or not self._ssnd_chunk:
raise Error, 'COMM chunk and/or SSND chunk missing'
diff --git a/Lib/test/Sine-1000Hz-300ms.aif b/Lib/test/Sine-1000Hz-300ms.aif
new file mode 100644
index 0000000..bf08f5c
--- /dev/null
+++ b/Lib/test/Sine-1000Hz-300ms.aif
Binary files differ
diff --git a/Lib/test/test_aifc.py b/Lib/test/test_aifc.py
new file mode 100644
index 0000000..58380e0
--- /dev/null
+++ b/Lib/test/test_aifc.py
@@ -0,0 +1,24 @@
+from test.test_support import findfile, run_unittest
+import unittest
+
+import aifc
+
+
+class AIFCTest(unittest.TestCase):
+
+ def setUp(self):
+ self.sndfilepath = findfile('Sine-1000Hz-300ms.aif')
+
+ def test_skipunknown(self):
+ #Issue 2245
+ #This file contains chunk types aifc doesn't recognize.
+ f = aifc.open(self.sndfilepath)
+ f.close()
+
+
+def test_main():
+ run_unittest(AIFCTest)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/Lib/test/test_sundry.py b/Lib/test/test_sundry.py
index 48cbcd6..cef155b 100644
--- a/Lib/test/test_sundry.py
+++ b/Lib/test/test_sundry.py
@@ -11,7 +11,6 @@
with warnings.catch_warnings():
warnings.simplefilter("ignore")
import CGIHTTPServer
- import aifc
import audiodev
import bdb
import cgitb
diff --git a/Misc/ACKS b/Misc/ACKS
index 4b409e1..d650b67 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -370,6 +370,7 @@
Peter van Kampen
Jacob Kaplan-Moss
Lou Kates
+Hiroaki Kawai
Sebastien Keim
Robert Kern
Randall Kern
@@ -541,6 +542,7 @@
Samuele Pedroni
Marcel van der Peijl
Steven Pemberton
+Santiago Peresón
Mark Perrego
Trevor Perrin
Tim Peters
diff --git a/Misc/NEWS b/Misc/NEWS
index efd57d4..7a8cb91 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -255,6 +255,8 @@
Library
-------
+- Issue #2245: aifc now skips chunk types it doesn't recognize, per spec.
+
- Issue #5874: distutils.tests.test_config_cmd is not locale-sensitive
anymore.