[vlc-commits] [Git][videolan/vlc][master] 10 commits: demux: libmp4: fix possible incomplete zlib output

Steve Lhomme (@robUx4) gitlab at videolan.org
Thu Apr 20 06:46:12 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
bf5b577a by Francois Cartegnie at 2023-04-20T06:26:39+00:00
demux: libmp4: fix possible incomplete zlib output

- - - - -
a42454ae by Francois Cartegnie at 2023-04-20T06:26:39+00:00
demux: libmp4: reject unknown cmov

- - - - -
d969fe03 by Francois Cartegnie at 2023-04-20T06:26:39+00:00
demux: libmp4: early reject unsupported cmov

- - - - -
5b728496 by Francois Cartegnie at 2023-04-20T06:26:39+00:00
demux: libmp4: regroup cmov atoms and restrict parsing

- - - - -
0acc3b28 by Francois Cartegnie at 2023-04-20T06:26:39+00:00
demux: libmp4: add missing backlink reset in BoxExtract

- - - - -
7d285df0 by Francois Cartegnie at 2023-04-20T06:26:39+00:00
demux: libmp4: remove useless cmov specific storage

refs #27812

- - - - -
50628837 by Francois Cartegnie at 2023-04-20T06:26:39+00:00
demux: libmp4: fix leakage on error

refs #27812

- - - - -
e860cfc0 by Francois Cartegnie at 2023-04-20T06:26:39+00:00
demux: libmp4: don't store uncompressed data on cmvd

- - - - -
b5a789a2 by Francois Cartegnie at 2023-04-20T06:26:39+00:00
demux: libmp4: simplify, deleting compression info after expansion

- - - - -
17a2f8d7 by Francois Cartegnie at 2023-04-20T06:26:39+00:00
demux: libmp4: check stream alloc

- - - - -


2 changed files:

- modules/demux/mp4/libmp4.c
- modules/demux/mp4/libmp4.h


Changes:

=====================================
modules/demux/mp4/libmp4.c
=====================================
@@ -281,6 +281,7 @@ MP4_Box_t * MP4_BoxExtract( MP4_Box_t **pp_chain, uint32_t i_type )
         {
             *pp_chain = p_box->p_next;
             p_box->p_next = NULL;
+            p_box->p_father = NULL;
             return p_box;
         }
         pp_chain = &p_box->p_next;
@@ -3418,8 +3419,6 @@ static int MP4_ReadBox_cmvd( stream_t *p_stream, MP4_Box_t *p_box )
     /* now copy compressed data */
     memcpy( p_box->data.p_cmvd->p_data, p_peek,i_read);
 
-    p_box->data.p_cmvd->b_compressed = 1;
-
 #ifdef MP4_VERBOSE
     msg_Dbg( p_stream, "read box: \"cmvd\" compressed data size %d",
                       p_box->data.p_cmvd->i_compressed_size );
@@ -3430,26 +3429,17 @@ static int MP4_ReadBox_cmvd( stream_t *p_stream, MP4_Box_t *p_box )
 
 static int MP4_ReadBox_cmov( stream_t *p_stream, MP4_Box_t *p_box )
 {
+#ifndef HAVE_ZLIB
+    msg_Dbg( p_stream, "read box: \"cmov\" zlib unsupported" );
+    return 0;
+#else
+
     MP4_Box_t *p_dcom;
     MP4_Box_t *p_cmvd;
 
-#ifdef HAVE_ZLIB
     stream_t *p_stream_memory;
     z_stream z_data;
     uint8_t *p_data;
-    int i_result;
-#endif
-
-    if( !( p_box->data.p_cmov = calloc(1, sizeof( MP4_Box_data_cmov_t ) ) ) )
-        return 0;
-
-    if( !p_box->p_father ||
-        ( p_box->p_father->i_type != ATOM_moov &&
-          p_box->p_father->i_type != ATOM_foov ) )
-    {
-        msg_Warn( p_stream, "Read box: \"cmov\" box alone" );
-        return 1;
-    }
 
     if( !MP4_ReadBoxContainer( p_stream, p_box ) )
     {
@@ -3471,11 +3461,6 @@ static int MP4_ReadBox_cmov( stream_t *p_stream, MP4_Box_t *p_box )
         return 0;
     }
 
-#ifndef HAVE_ZLIB
-    msg_Dbg( p_stream, "read box: \"cmov\" zlib unsupported" );
-    return 0;
-
-#else
     /* decompress data */
     /* allocate a new buffer */
     if( !( p_data = malloc( p_cmvd->data.p_cmvd->i_uncompressed_size ) ) )
@@ -3498,10 +3483,10 @@ static int MP4_ReadBox_cmov( stream_t *p_stream, MP4_Box_t *p_box )
     }
 
     /* uncompress */
-    i_result = inflate( &z_data, Z_NO_FLUSH );
-    if( i_result != Z_OK && i_result != Z_STREAM_END )
+    if( inflate( &z_data, Z_FINISH ) != Z_STREAM_END )
     {
         msg_Err( p_stream, "read box: \"cmov\" error while uncompressing" );
+        inflateEnd( &z_data );
         free( p_data );
         return 0;
     }
@@ -3511,7 +3496,6 @@ static int MP4_ReadBox_cmov( stream_t *p_stream, MP4_Box_t *p_box )
         msg_Warn( p_stream, "read box: \"cmov\" uncompressing data size "
                   "mismatch" );
     }
-    p_cmvd->data.p_cmvd->i_uncompressed_size = z_data.total_out;
 
     /* close zlib */
     if( inflateEnd( &z_data ) != Z_OK )
@@ -3520,28 +3504,30 @@ static int MP4_ReadBox_cmov( stream_t *p_stream, MP4_Box_t *p_box )
                   "data (ignored)" );
     }
 
-    free( p_cmvd->data.p_cmvd->p_data );
-    p_cmvd->data.p_cmvd->p_data = p_data;
-    p_cmvd->data.p_cmvd->b_compressed = 0;
-
     msg_Dbg( p_stream, "read box: \"cmov\" box successfully uncompressed" );
 
     /* now create a memory stream */
-    p_stream_memory =
-        vlc_stream_MemoryNew( VLC_OBJECT(p_stream),
-                              p_cmvd->data.p_cmvd->p_data,
-                              p_cmvd->data.p_cmvd->i_uncompressed_size, true );
+    p_stream_memory = vlc_stream_MemoryNew( VLC_OBJECT(p_stream),
+                                            p_data, z_data.total_out, false );
+    if( !p_stream_memory )
+    {
+        free( p_data );
+        return 0;
+    }
 
     /* and read uncompressd moov */
-    p_box->data.p_cmov->p_moov = MP4_ReadBox( p_stream_memory, NULL );
+    MP4_Box_t *p_moov =  MP4_ReadBox( p_stream_memory, NULL );
 
     vlc_stream_Delete( p_stream_memory );
 
+    if( p_moov )
+        MP4_BoxAddChild( p_box, p_moov );
+
 #ifdef MP4_VERBOSE
     msg_Dbg( p_stream, "read box: \"cmov\" compressed movie header completed");
 #endif
 
-    return p_box->data.p_cmov->p_moov ? 1 : 0;
+    return p_moov ? 1 : 0;
 #endif /* HAVE_ZLIB */
 }
 
@@ -4938,7 +4924,6 @@ static const struct
 {
     /* Containers */
     { ATOM_moov,    MP4_ReadBoxContainer,     0 },
-    { ATOM_foov,    MP4_ReadBoxContainer,     0 },
     { ATOM_trak,    MP4_ReadBoxContainer,     ATOM_moov },
     { ATOM_trak,    MP4_ReadBoxContainer,     ATOM_foov },
     { ATOM_mdia,    MP4_ReadBoxContainer,     ATOM_trak },
@@ -4970,10 +4955,16 @@ static const struct
     { ATOM_mvex,    MP4_ReadBoxContainer,     ATOM_moov },
     { ATOM_mvex,    MP4_ReadBoxContainer,     ATOM_ftyp },
 
+    /* Quicktime compression */
+    { ATOM_foov,    MP4_ReadBoxContainer,     0 },
+    { ATOM_cmov,    MP4_ReadBox_cmov,         ATOM_foov },
+    { ATOM_cmov,    MP4_ReadBox_cmov,         ATOM_moov },
+    { ATOM_dcom,    MP4_ReadBox_dcom,         ATOM_cmov },
+    { ATOM_cmvd,    MP4_ReadBox_cmvd,         ATOM_cmov },
+
     /* specific box */
     { ATOM_ftyp,    MP4_ReadBox_ftyp,         0 },
     { ATOM_styp,    MP4_ReadBox_ftyp,         0 },
-    { ATOM_cmov,    MP4_ReadBox_cmov,         0 },
     { ATOM_mvhd,    MP4_ReadBox_mvhd,         ATOM_moov },
     { ATOM_mvhd,    MP4_ReadBox_mvhd,         ATOM_foov },
     { ATOM_tkhd,    MP4_ReadBox_tkhd,         ATOM_trak },
@@ -5007,9 +4998,7 @@ static const struct
     { ATOM_esds,    MP4_ReadBox_esds,         ATOM_mp4a },
     { ATOM_esds,    MP4_ReadBox_esds,         ATOM_mp4v },
     { ATOM_esds,    MP4_ReadBox_esds,         ATOM_mp4s },
-    { ATOM_dcom,    MP4_ReadBox_dcom,         0 },
     { ATOM_dfLa,    MP4_ReadBox_Binary,       ATOM_fLaC },
-    { ATOM_cmvd,    MP4_ReadBox_cmvd,         0 },
     { ATOM_av1C,    MP4_ReadBox_av1C,         ATOM_av01 },
     { ATOM_avcC,    MP4_ReadBox_avcC,         ATOM_avc1 },
     { ATOM_avcC,    MP4_ReadBox_avcC,         ATOM_avc3 },
@@ -5492,29 +5481,19 @@ MP4_Box_t *MP4_BoxGetRoot( stream_t *p_stream )
             goto error;
     }
 
-    MP4_Box_t *p_moov;
     MP4_Box_t *p_cmov;
-
     /* check if there is a cmov, if so replace
       compressed moov by  uncompressed one */
-    if( ( ( p_moov = MP4_BoxGet( p_vroot, "moov" ) ) &&
-          ( p_cmov = MP4_BoxGet( p_vroot, "moov/cmov" ) ) ) ||
-        ( ( p_moov = MP4_BoxGet( p_vroot, "foov" ) ) &&
-          ( p_cmov = MP4_BoxGet( p_vroot, "foov/cmov" ) ) ) )
+    if( ( p_cmov = MP4_BoxGet( p_vroot, "moov/cmov" ) ) ||
+        ( p_cmov = MP4_BoxGet( p_vroot, "foov/cmov" ) ) )
     {
-        /* rename the compressed moov as a box to skip */
-        p_moov->i_type = ATOM_skip;
-
+        MP4_Box_t *p_moov = MP4_BoxExtract( &p_vroot->p_first, p_cmov->p_father->i_type );
         /* get uncompressed p_moov */
-        p_moov = p_cmov->data.p_cmov->p_moov;
-        p_cmov->data.p_cmov->p_moov = NULL;
-
+        MP4_Box_t *p_umoov = MP4_BoxExtract( &p_cmov->p_first, ATOM_moov );
         /* make p_root father of this new moov */
-        p_moov->p_father = p_vroot;
-
-        /* insert this new moov box as first child of p_root */
-        p_moov->p_next = p_vroot->p_first;
-        p_vroot->p_first = p_moov;
+        MP4_BoxAddChild( p_vroot, p_umoov );
+        /* Release old moov and compressed info */
+        MP4_BoxFree( p_moov );
     }
 
     return p_vroot;


=====================================
modules/demux/mp4/libmp4.h
=====================================
@@ -1077,18 +1077,10 @@ typedef struct MP4_Box_data_cmvd_s
 {
     uint32_t i_uncompressed_size;
     uint32_t i_compressed_size;
-
-    int     b_compressed; /* Set to 1 if compressed data, 0 if uncompressed */
     uint8_t *p_data;
 
 } MP4_Box_data_cmvd_t;
 
-typedef struct MP4_Box_data_cmov_s
-{
-    struct MP4_Box_s *p_moov; /* uncompressed moov */
-
-} MP4_Box_data_cmov_t;
-
 typedef struct
 {
     uint32_t i_type;
@@ -1819,7 +1811,6 @@ typedef union MP4_Box_data_s
 
     MP4_Box_data_dcom_t *p_dcom;
     MP4_Box_data_cmvd_t *p_cmvd;
-    MP4_Box_data_cmov_t *p_cmov;
 
     MP4_Box_data_moviehintinformation_rtp_t *p_moviehintinformation_rtp;
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/9811a0d67a25dd60a42cd099c433ff357de7434a...17a2f8d7602c0c58be57873767b79f42a2140aea

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/9811a0d67a25dd60a42cd099c433ff357de7434a...17a2f8d7602c0c58be57873767b79f42a2140aea
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list