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.
This commit is contained in:
R. David Murray 2009-04-29 13:17:37 +00:00
parent a1b91d944b
commit 25b4add5b0
6 changed files with 28 additions and 8 deletions

View File

@ -144,9 +144,6 @@ class Error(Exception):
_AIFC_version = 0xA2805140L # Version 1 of AIFF-C _AIFC_version = 0xA2805140L # Version 1 of AIFF-C
_skiplist = 'COMT', 'INST', 'MIDI', 'AESD', \
'APPL', 'NAME', 'AUTH', '(c) ', 'ANNO'
def _read_long(file): def _read_long(file):
try: try:
return struct.unpack('>l', file.read(4))[0] return struct.unpack('>l', file.read(4))[0]
@ -314,10 +311,6 @@ class Aifc_read:
self._version = _read_ulong(chunk) self._version = _read_ulong(chunk)
elif chunkname == 'MARK': elif chunkname == 'MARK':
self._readmark(chunk) self._readmark(chunk)
elif chunkname in _skiplist:
pass
else:
raise Error, 'unrecognized chunk type '+chunk.chunkname
chunk.skip() chunk.skip()
if not self._comm_chunk_read or not self._ssnd_chunk: if not self._comm_chunk_read or not self._ssnd_chunk:
raise Error, 'COMM chunk and/or SSND chunk missing' raise Error, 'COMM chunk and/or SSND chunk missing'

Binary file not shown.

24
Lib/test/test_aifc.py Normal file
View File

@ -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()

View File

@ -11,7 +11,6 @@ class TestUntestedModules(unittest.TestCase):
with warnings.catch_warnings(): with warnings.catch_warnings():
warnings.simplefilter("ignore") warnings.simplefilter("ignore")
import CGIHTTPServer import CGIHTTPServer
import aifc
import audiodev import audiodev
import bdb import bdb
import cgitb import cgitb

View File

@ -370,6 +370,7 @@ Tamito Kajiyama
Peter van Kampen Peter van Kampen
Jacob Kaplan-Moss Jacob Kaplan-Moss
Lou Kates Lou Kates
Hiroaki Kawai
Sebastien Keim Sebastien Keim
Robert Kern Robert Kern
Randall Kern Randall Kern
@ -541,6 +542,7 @@ Randy Pausch
Samuele Pedroni Samuele Pedroni
Marcel van der Peijl Marcel van der Peijl
Steven Pemberton Steven Pemberton
Santiago Peresón
Mark Perrego Mark Perrego
Trevor Perrin Trevor Perrin
Tim Peters Tim Peters

View File

@ -255,6 +255,8 @@ Core and Builtins
Library 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 - Issue #5874: distutils.tests.test_config_cmd is not locale-sensitive
anymore. anymore.