Fuzzing fixes#63
Open
bobsayshilol wants to merge 10 commits into
Open
Conversation
See comment for why this change is necessary.
MP4File::GetTrackH264SeqPictHeaders() can return early if it fails to parse or allocate, which means that MP4GetTrackH264SeqPictHeaders() can return success and look like the pointers need freeing even though some may still be nullptrs. To fix this, guard the derefs.
We need an extra byte for the terminating NUL, otherwise the strncat() can write past the end or the caller can read past the end of the string.
DeleteChildAtom() doesn't delete the child atom, it only removes it. Some uses of it are only for reparenting and not deleting, and it seemed invasive to rename the symbol since it's widely used, so just plug the leaks.
GetBytesProperty() allocates its return value, so remember to free it. Also change the types to be consistent to avoid an unnecessary cast.
InsertChildAtom() does a NULL check of pParentAtom before it's used, but that happens too late when called here. Add an ASSERT() to catch that issue.
ASAN flags up that these read out of bounds on bad data.
MP4ConvertTime() can throw on bad data which ends up leaking |chapters| since it's not owned by anything. Add some RAII to plug that leak.
It's UB to pass a nullptr into operator<<(ostream&, char*), which happens in MP4Atom::ReadProperties()'s ostringstream on invalid data. libstdc++ "implements" this UB by ignoring the nullptr along with everything that comes after it, and libc++ crashes. Neither of these are good, so return a placeholder if it's a nullptr. Note that GetName() only appears to be used for logging messages so it shouldn't affect behaviour.
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.
This PR fixes a few issues found via fuzzing.
See individual commits for more details.
Sanitizer output below:
f9e7fae - Avoid leaking memory if |new MP4BytesProperty()| throws
caa7244 - Fix an OOM and stack overflow
Also causes an OOM with a different input due to an infinite number of children being added to a single atom (compared to "atom with a single child" being a child of itself in the above
stack-overflow)e8746b4 - Fix crash on nullptr
da83dca - Fix read/write out of bounds due to off-by-one error
20c06a4 - Fix a couple more leaks
ba33c0d - Plug another leak
044f0fb - Guard against NULL deref
03e9718 - Bounds check tag sizes before attempting to read them
3d78dcf - Plug a leak if an exception is thrown
afa7205 - Fix crash when using libc++