Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sndhdr.what() does not recognize wav file #44318

Closed
klankschap mannequin opened this issue Dec 9, 2006 · 9 comments
Closed

sndhdr.what() does not recognize wav file #44318

klankschap mannequin opened this issue Dec 9, 2006 · 9 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@klankschap
Copy link
Mannequin

klankschap mannequin commented Dec 9, 2006

BPO 1611944
Files
  • Audio01.rar: wav in rar archive
  • sndhdr.diff: Patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2006-12-09.02:37:48.000>
    labels = ['type-bug', 'library']
    title = 'sndhdr.what() does not recognize wav file'
    updated_at = <Date 2020-09-19.19:04:33.906>
    user = 'https://bugs.python.org/klankschap'

    bugs.python.org fields:

    activity = <Date 2020-09-19.19:04:33.906>
    actor = 'georg.brandl'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2006-12-09.02:37:48.000>
    creator = 'klankschap'
    dependencies = []
    files = ['2251', '11501']
    hgrepos = []
    issue_num = 1611944
    keywords = ['patch']
    message_count = 7.0
    messages = ['30765', '30766', '30767', '30768', '30769', '30770', '73294']
    nosy_count = 2.0
    nosy_names = ['klankschap', 'matthijs']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'test needed'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue1611944'
    versions = ['Python 3.1', 'Python 2.7', 'Python 3.2']

    @klankschap
    Copy link
    Mannequin Author

    klankschap mannequin commented Dec 9, 2006

    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.

    @klankschap klankschap mannequin added the stdlib Python modules in the Lib dir label Dec 9, 2006
    @birkenfeld
    Copy link
    Member

    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?

    @klankschap
    Copy link
    Mannequin Author

    klankschap mannequin commented Dec 9, 2006

    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

    @klankschap
    Copy link
    Mannequin Author

    klankschap mannequin commented Dec 9, 2006

    Apparently the sndhdr.what() function does not skip the embedded comment chunk at the start.

    @birkenfeld
    Copy link
    Member

    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?

    @klankschap
    Copy link
    Mannequin Author

    klankschap mannequin commented Dec 9, 2006

    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

    @matthijs
    Copy link
    Mannequin

    matthijs mannequin commented Sep 16, 2008

    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.

    @BreamoreBoy BreamoreBoy mannequin added the type-bug An unexpected behavior, bug, or error label Aug 25, 2010
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @hugovk
    Copy link
    Member

    hugovk commented Apr 12, 2022

    Note the sndhdr module is deprecated in 3.11 and set for removal in 3.13.

    See PEP 594 – Removing dead batteries from the standard library and #91217.

    @AlexWaygood
    Copy link
    Member

    Note the sndhdr module is deprecated in 3.11 and set for removal in 3.13.

    See PEP 594 – Removing dead batteries from the standard library and #91217.

    snhdr has been deprecated in part because it has no active maintainer in the core dev team. Now that the module is deprecated, bugfixes and improvements to the module will be low priority; moreover, the fact that this issue has not seen any activity since 2008 indicates that this problem probably does not affect a large number of users. I am therefore closing this issue.

    Cc. @klankschap, @matthijs

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants