Repository navigation
Conversation
This branch has not been deployed
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.
Base branch:
dev-0.12Summary
When a decoder's backend initializes but post-initialization fails, cleanup runs twice:
ma_decoder__postinit()callsma_decoder_uninit(), which uninitializes and frees the backend.ma_decoder__postinit_or_uninit()then calls the backend'sonUninitagain, on the freed backend.ma_decoder__init_data_converter()uninitializes the data converter.ma_decoder__postinit()then callsma_decoder_uninit(), which uninitializes it again.The first doesn't need an allocation to fail, only a file that post-initialization rejects, so a damaged file can trigger it. A WAV file with 255 channels is enough: dr_wav accepts it, but
MA_MAX_CHANNELSis 254, soma_data_converter_init()returnsMA_INVALID_ARGS. Without a sanitizer, the program below ends with:ma_decoder_init_memory(),ma_decoder_init()andma_decoder_init_vfs()all reach it.devdoesn't have the first problem: it has noma_decoder__postinit_or_uninit(), and callsma_decoder__postinit()directly. The function arrived on this branch in 99c5a9c.The fix
ma_decoder__postinit_or_uninit()and callma_decoder__postinit()instead, asdevdoes. It already cleans up on failure.ma_decoder__init_data_converter(), don't uninitialize the converter on the two input cache errors.ma_decoder__postinit()is its only caller, and it uninitializes the converter along with the rest of the decoder.Reproduction
Before, on 17464df:
After:
The second problem needs an allocation to fail. This program fails each allocation in turn, while opening a decoder that resamples. Put it next to the first one.
Before, it reports the same use-after-free as above. With only the first change, it reports the second problem:
After:
Failed each of 3 allocations in turn., and no reports.Testing
Linux x86-64, GCC:
ma_decoder_init_memory(),ma_decoder_init(),ma_decoder_init_file()andma_decoder_init_vfs(), with-fsanitize=address,undefined. No crashes. The only reports are leaks from the first problem below.ma_decoder_init()andma_decoder_init_file()as well. No crashes. The only reports are leaks from the two problems below.miniaudio.hcompiles without warnings as C++ with-Wall -Wextra, and the first program compiles without warnings with-std=c89 -pedantic -Wall -Wextra, leaving aside the existinglong longwarnings.