validate MONO_FLAG against channel count in legacy open_file3#241
Merged
Conversation
A version 3 file sets config.num_channels from the WAV NumChannels field while the decoder picks the mono or stereo path from MONO_FLAG, and the two are never reconciled, so NumChannels==1 with MONO_FLAG clear runs the stereo path into a one-channel output buffer.
Owner
|
Looks good, thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Built with
--enable-legacy, a guard page placed one int past the decode buffer:open_file3takesconfig.num_channelsfrom the WAVfmtNumChannels field, so the caller sizes its buffer for one channel.unpack_samples3instead chooses the mono or stereo path from the version 3 header'sMONO_FLAGbit. Below version 3 the two agree, because the flags are recomputed from NumChannels a few lines up, but a version 3 file carries its own flags andopen_file3never checks them against NumChannels.So NumChannels == 1 with
MONO_FLAGclear reports one channel yet runs the stereo path, which writes two samples per frame (*bptr++twice) past the caller's buffer. Found feeding crafted v3 headers to the stand-alone fuzzer: the stereo loop smashes the 1024-int decode buffer on the firstWavpackUnpackSamplescall (stack-smashing abort under-fstack-protector-all, heap overrun under asan). The inverse, NumChannels == 2 withMONO_FLAGset, only under-writes, but is wrong as well.Reconciled at the open, matching the pre-3 path. The regression file aborts before the patch and is rejected cleanly after.