This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: sndhdr.what() does not recognize wav file
Type: behavior Stage: test needed
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: klankschap, matthijs
Priority: normal Keywords: patch

Created on 2006-12-09 02:37 by klankschap, last changed 2022-04-11 14:56 by admin.

Files
File name Uploaded Description Edit
Audio01.rar klankschap, 2006-12-09 09:55 wav in rar archive
sndhdr.diff matthijs, 2008-09-16 11:38 Patch
Messages (7)
msg30765 - (view) Author: Floris van Manen (klankschap) Date: 2006-12-09 02:37
using 2.5 on osx 10.4
the sndhdr.what() function fails to recognize some wav headers.
however these wav files are recognized correctly by other 'standard' applications like quicktime and itunes.

msg30766 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-12-09 08:55
We'd need some more information about these specific wave files in order to improve sndhdr.what().

Can you try to find out why they aren't recognized correctly, or what their header (sndhdr reads the first 512 bytes) looks like?
msg30767 - (view) Author: Floris van Manen (klankschap) Date: 2006-12-09 09:56
Attached you find (in a rar file) a 260kb wav file, 2 tracks, 24 bit, 44.1kHz
You can play it, ask either OSX or XP to show the properties.
Yet sndhdr.what() returns None


File Added: Audio01.rar
msg30768 - (view) Author: Floris van Manen (klankschap) Date: 2006-12-09 10:02
Apparently the sndhdr.what() function does not skip the embedded comment chunk at the start.
msg30769 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-12-09 10:26
I see. The problem is, as the "bext" chunk can be arbitrarily long, the test function would need more than 512 bytes to read the "fmt " chunk, or it could return that it cannot read the format details.

Would you like to work on a patch?
msg30770 - (view) Author: Floris van Manen (klankschap) Date: 2006-12-09 12:01
this could be a start. 
however the initial 512 bytes might be too short.
i don't see (yet) how to increase that in a snazzy way. 
i just changed it into a read(1024)

def test_wav_test( h ):
    if h[:4] != 'RIFF' or h[8:12] != 'WAVE':
        return None
    if h[12:16] == 'fmt ':
        style = get_short_le(h[20:22])
        nchannels = get_short_le(h[22:24])
        rate = get_long_le(h[24:28])
        sample_bits = get_short_le(h[34:36])
        return 'wav', rate, nchannels, -1, sample_bits
    elif h[12:16] == 'bext':
        offset = 12
        while True:
            try:
                if h[offset:offset+4] == 'fmt ':
                    nchannels =  get_short_le( h[offset+10:offset+12] )
                    rate = get_long_le( h[offset+12:offset+16] )
                    sample_bits =  get_short_le( h[offset+22:offset+24] )
                    return 'wav', rate, nchannels, -1, sample_bits
                offset += ( get_long_le( h[offset+4:offset+8] ) + 8 )
            except IndexError:
                print 'header buffer too short'
                return None
msg73294 - (view) Author: Matthijs Kooijman (matthijs) Date: 2008-09-16 11:38
I've written a new patch, which works a bit better. You can find the new
patch attached.

I've restructed the patch to prevent code duplication. Also, it now
works with other chunks than bext (I had a file with a list chunk which
triggered my interest in this bug). This is done with a hardcoded list
of valid chunks. However, it seems that there is no complete list of
valid chunk types, so it might be better to remove the chunk type check
alltogether.

Also, this patch explicitly checks for overflow, since taking a slice of
a sequence does not seem to trigger an IndexError, but just return an
empty sequence.
History
Date User Action Args
2022-04-11 14:56:21adminsetgithub: 44318
2020-09-19 19:04:33georg.brandlsetnosy: - georg.brandl
2010-08-25 14:36:32BreamoreBoysetstage: test needed
type: behavior
versions: + Python 3.2
2008-09-16 20:40:25benjamin.petersonsetversions: + Python 3.1, Python 2.7, - Python 2.5
2008-09-16 11:38:48matthijssetfiles: + sndhdr.diff
nosy: + matthijs
messages: + msg73294
keywords: + patch
2006-12-09 02:37:48klankschapcreate