access: bluray: check for overlay pointer overwrite
authorFrancois Cartegnie <fcvlcdev@free.fr>
Fri, 6 Mar 2020 16:02:46 +0000 (17:02 +0100)
committerFrancois Cartegnie <fcvlcdev@free.fr>
Mon, 9 Mar 2020 09:39:56 +0000 (10:39 +0100)
modules/access/bluray.c

index 8c6f285..3d20b53 100644 (file)
@@ -1840,25 +1840,6 @@ static void blurayActivateOverlay(demux_t *p_demux, int plane)
     vlc_mutex_unlock(&ov->lock);
 }
 
-static void blurayInitOverlay(demux_t *p_demux, int plane, int width, int height)
-{
-    demux_sys_t *p_sys = p_demux->p_sys;
-
-    assert(p_sys->bdj.p_overlays[plane] == NULL);
-
-    bluray_overlay_t *ov = calloc(1, sizeof(*ov));
-    if (unlikely(ov == NULL))
-        return;
-
-    ov->width = width;
-    ov->height = height;
-    ov->b_on_vout = false;
-
-    vlc_mutex_init(&ov->lock);
-
-    p_sys->bdj.p_overlays[plane] = ov;
-}
-
 /**
  * Destroy every regions in the subpicture.
  * This is done in two steps:
@@ -1884,6 +1865,31 @@ static void blurayClearOverlay(demux_t *p_demux, int plane)
     vlc_mutex_unlock(&ov->lock);
 }
 
+static void blurayInitOverlay(demux_t *p_demux, int plane, int width, int height)
+{
+    demux_sys_t *p_sys = p_demux->p_sys;
+
+    if(p_sys->bdj.p_overlays[plane])
+    {
+        /* Should not happen */
+        msg_Warn( p_demux, "Trying to init over an existing overlay" );
+        blurayClearOverlay( p_demux, plane );
+        blurayCloseOverlay( p_demux, plane );
+    }
+
+    bluray_overlay_t *ov = calloc(1, sizeof(*ov));
+    if (unlikely(ov == NULL))
+        return;
+
+    ov->width = width;
+    ov->height = height;
+    ov->b_on_vout = false;
+
+    vlc_mutex_init(&ov->lock);
+
+    p_sys->bdj.p_overlays[plane] = ov;
+}
+
 /*
  * This will draw to the overlay by adding a region to our region list
  * This will have to be copied to the subpicture used to render the overlay.