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
Comments
using 2.5 on osx 10.4 |
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? |
Attached you find (in a rar file) a 260kb wav file, 2 tracks, 24 bit, 44.1kHz File Added: Audio01.rar |
Apparently the sndhdr.what() function does not skip the embedded comment chunk at the start. |
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? |
this could be a start. 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 |
I've written a new patch, which works a bit better. You can find the new I've restructed the patch to prevent code duplication. Also, it now Also, this patch explicitly checks for overflow, since taking a slice of |
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. |
Cc. @klankschap, @matthijs |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: