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

Extra \0 bytes in RIFF INFO tags causes wav_info_read() to raise ArgumentError #101

Closed
cHemingway opened this issue Jun 16, 2021 · 2 comments · Fixed by #103
Closed

Extra \0 bytes in RIFF INFO tags causes wav_info_read() to raise ArgumentError #101

cHemingway opened this issue Jun 16, 2021 · 2 comments · Fixed by #103

Comments

@cHemingway
Copy link
Contributor

I am trying to read a file where extra padding/termination bytes are present in the RIFF INFO tags, so wav_info_read(chunks) throws an exception.

ERROR: LoadError: ArgumentError: Symbol name may not contain \0
Stacktrace:
 [1] Symbol
   @ .\boot.jl:480 [inlined]
 [2] read_tag(tags::Dict{Symbol, String}, t::Vector{UInt8})
   @ WAV [snipped]\WAV\src\WAVChunk.jl:210
 [3] wav_info_read(chunks::Vector{WAVChunk})
   @ WAV [snipped]\WAV\src\WAVChunk.jl:250

This appears to be because the (private) function read_tag does not skip over multiple '\0' characters before returning the new list_data t.
Instead, it calls return t[(i+1):end] which would only skip one character.
On the next call to read_tag(), the first line of the function will then attempt to execute:

tag_id = Symbol(String("\0ABC"))

which will raise the ArgumentError as shown before.

I think I have a working fix for this, and will submit it as a pull request.

cHemingway added a commit to cHemingway/WAV.jl that referenced this issue Jun 16, 2021
Some WAV files contain extra consecutive \0 bytes in RIFF INFO section, which causes issues if not skipped over properly. See dancasimiro#101 for details
CMGeldenhuys added a commit to CMGeldenhuys/WAV.jl that referenced this issue Jun 21, 2021
Some WAVE files are not just padded with \0 bytes (null terminators) but
arbitrary bytes. This causes the bug outlined in dancasimiro#101 & dancasimiro#102. Instead of
looking for consecutive \0 bytes read size from CHUNK and ignore
remainder of unused data.

See dancasimiro#101, dancasimiro#102
CMGeldenhuys added a commit to CMGeldenhuys/WAV.jl that referenced this issue Jun 21, 2021
Some WAVE files are not just padded with \0 bytes (null terminators) but
arbitrary bytes. This causes the bug outlined in dancasimiro#101 & dancasimiro#102. Instead of
looking for consecutive \0 bytes read size from CHUNK and ignore
remainder of unused data.

See dancasimiro#101, dancasimiro#102
@CMGeldenhuys
Copy link
Contributor

An alternative fix might be to utilise the size field present in the subchunk block. This would allow one to skip arbitrary bytes instead of relying on the string being null padded beyond its null termination.

dancasimiro added a commit that referenced this issue Jun 26, 2021
Fix #101, make read_tags skip extra arbitrary bytes
dancasimiro added a commit that referenced this issue Jun 26, 2021
Includes fixes for
#95 -- optimize read_pcm_samples
#101 -- Fix bug where tags with multiple nulls exploded.
@cHemingway
Copy link
Contributor Author

That fix looks better to me! I should have seen the size field

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants