ffmpeg sigbus top crash android ref base inc strong void const #9
Open
rlavarec-gpsw wants to merge 1 commit intogopro-7.1-patchedfrom
Conversation
Root Cause The crash occurs when MediaCodec.configure() receives a Java Surface object whose native peer has been released (Surface.release() or SurfaceTexture.release() was called). The Java object is still a valid JNI reference, but its internal mNativeObject field is 0/NULL. When the Android framework calls getSurface() -> RefBase::incStrong() on this null native pointer, it crashes with a null dereference in the atomic operation. The call path: control_thread -> op_start -> init_mediacodec -> avcodec_open2 -> FFmpeg mediacodec init -> MediaCodec.configure(format, surface, null, flags) -> CRASH. Fixes Applied (defense in depth, 3 layers) 1. mediacodec_surface.c:30: Added is_surface_valid() helper that calls Surface.isValid() via JNI, and integrated it into ff_mediacodec_surface_ref(). When the Surface is invalid, it returns NULL instead of creating a reference to a dead surface. This causes s->surface to be NULL in the decoder, preventing the crash. 2. mediacodec_wrapper.c: Added Surface.isValid() checks in both: mediacodec_jni_configure() -> before calling MediaCodec.configure() via JNI (the exact crash path from the stack trace) mediacodec_ndk_configure() -> before calling ANativeWindow_fromSurface() (which would also crash with the same issue) Both return AVERROR_EXTERNAL if the Surface is invalid, which is handled gracefully by the callers (configure failure -> decoder fallback or retry).
Collaborator
Author
leifterry-gpsw
approved these changes
Apr 17, 2026
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.
MAGMA-6468