[FFmpeg-devel,1/6] avcodec/mediacodec_surface: guard against NULL surface

Submitted by Aman Gupta on Sept. 5, 2019, 6:27 p.m.

Details

Message ID 20190905182735.65987-1-ffmpeg@tmm1.net
State New
Headers show

Commit Message

Aman Gupta Sept. 5, 2019, 6:27 p.m.
From: Aman Gupta <aman@tmm1.net>

Signed-off-by: Aman Gupta <aman@tmm1.net>
---
 libavcodec/mediacodec_surface.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Matthieu Bouron Sept. 6, 2019, 8:27 a.m.
On Thu, Sep 05, 2019 at 11:27:30AM -0700, Aman Gupta wrote:
> From: Aman Gupta <aman@tmm1.net>
> 
> Signed-off-by: Aman Gupta <aman@tmm1.net>
> ---
>  libavcodec/mediacodec_surface.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/mediacodec_surface.c b/libavcodec/mediacodec_surface.c
> index aada1ecebe..efcc4dc63c 100644
> --- a/libavcodec/mediacodec_surface.c
> +++ b/libavcodec/mediacodec_surface.c
> @@ -28,9 +28,11 @@
>  void *ff_mediacodec_surface_ref(void *surface, void *log_ctx)
>  {
>      JNIEnv *env = NULL;
> -
>      void *reference = NULL;
>  
> +    if (!surface)
> +        return NULL;
> +
>      env = ff_jni_get_env(log_ctx);
>      if (!env) {
>          return NULL;
> -- 
> 2.20.1
> 

This should not be needed unless it fixes a crash.
NewGlobalRef/DeleteGlobalRef (as well as NewLocalRef/DeleteLocalRef)
handles NULL pointers. The JNI MediaCodec wrapper is missleading about
this as it does this kind of unneeded checks everywhere (I did not known
at the time that the ref functions handle NULL). I have a local branch
cleaning this up. I will submit it to the ML in the upcoming days.

Patch hide | download patch | download mbox

diff --git a/libavcodec/mediacodec_surface.c b/libavcodec/mediacodec_surface.c
index aada1ecebe..efcc4dc63c 100644
--- a/libavcodec/mediacodec_surface.c
+++ b/libavcodec/mediacodec_surface.c
@@ -28,9 +28,11 @@ 
 void *ff_mediacodec_surface_ref(void *surface, void *log_ctx)
 {
     JNIEnv *env = NULL;
-
     void *reference = NULL;
 
+    if (!surface)
+        return NULL;
+
     env = ff_jni_get_env(log_ctx);
     if (!env) {
         return NULL;