[issue9243] sndhdr erroneously detects files as vox

James Lee report at bugs.python.org
Tue Jul 13 13:47:49 CEST 2010

New submission from James Lee <jbit at jbit.net>:

http://svn.python.org/view/python/branches/py3k/Lib/sndhdr.py?r1=56957&r2=56987 seems to have broken sndhdr as it incorrectly detects files as voc (all that time ago and nobody has noticed...):

[jbit at miku]~$ xxd test.wav | head -n 1
0000000: 5249 4646 2478 e001 5741 5645 666d 7420  RIFF$x..WAVEfmt 
[jbit at miku]~$ python3.1
>>> import sndhdr
>>> sndhdr.what("test.wav")
('voc', 0, 1, -1, 8)

I'm a little unsure why it got changed from indexing to startswith() at all, but changes like the following are just totally incorrect.
-    if h[:20] != b'Creative Voice File\032':
+    if h.startswith(b'Creative Voice File\032'):

Attached is a patch against the py3k branch which fixes the issue as well as some other things obviously broken by the same changelist, although it might be a good idea to review the changelist again to make sure there's nothing else obviously broken :)
>>> sndhdr.what("test.wav")
('wav', 48000, 2, -1, 16)

components: Library (Lib)
files: sndhdr-fix.patch
keywords: patch
messages: 110172
nosy: jbit
priority: normal
severity: normal
status: open
title: sndhdr erroneously detects files as vox
type: behavior
versions: Python 3.1
Added file: http://bugs.python.org/file17981/sndhdr-fix.patch

Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list