src/common_utils.c: bound reorder copy in WavpackGetChannelLayout#252
src/common_utils.c: bound reorder copy in WavpackGetChannelLayout#252aizu-m wants to merge 2 commits into
Conversation
|
Thanks for the bug report! I have dug into this a little and have the following observations:
|
…nel count The layout channel count is read verbatim from the NEW_CONFIG metadata in read_new_config_info(). It only becomes verifiable once the real channel count is known (after the MONO_FLAG fallback for files without a CHANNEL_INFO block), so flag the mismatch in WavpackOpenFileInputEx64() and reject the file there. Revert the fuzzer change: real callers size the reorder buffer by the layout count per the library docs, so the harness should too.
|
Both points make sense, thanks for digging in.
Traced it back through: the regression file (255-channel layout on a 2-channel file) now fails to open with "invalid channel layout in file!", and the 19 valid files in the seed corpus and regression set all still open clean. |
Turned up while fuzzing the file-open path under ASan: a crafted 2-channel file declares 255 channels in its NEW_CONFIG layout word, and WavpackGetChannelLayout copies (channel_layout & 0xff) bytes from channel_reordering. That count is taken straight from the metadata in read_new_config_info and is never checked against the real channel count.
Per the discussion, the proper fix lives at open time. read_new_config_info can't do the check itself, but by the point WavpackOpenFileInputEx64 finalises num_channels (including the MONO_FLAG fallback for files with no CHANNEL_INFO block) the channel count is known, so the layout count is verifiable there. A layout claiming more channels than the file has is invalid, so the file is rejected with "invalid channel layout in file!".
The bound added in WavpackGetChannelLayout stays as a backstop.
Fuzzer change reverted: the harness sizes its reorder buffer by the layout count, matching the library docs and the command-line tools.
Regression file fuzzing/regression/new-config-channel-reorder-overflow.wv (255-channel layout on a 2-channel file) is now rejected at open; all valid corpus files still open.