[vlc-commits] [Git][videolan/vlc][3.0.x] 6 commits: demux: ogg: don't set up unknown streams

François Cartegnie (@fcartegnie) gitlab at videolan.org
Tue Sep 1 15:19:51 UTC 2026



François Cartegnie pushed to branch 3.0.x at VideoLAN / VLC


Commits:
8103e0cb by François Cartegnie at 2026-09-01T17:10:59+02:00
demux: ogg: don't set up unknown streams

(cherry picked from commit 1a1d764a4d6e200ea26128a0f3f5cbdb008195ae)

- - - - -
d378533e by François Cartegnie at 2026-09-01T17:10:59+02:00
demux: ogg: fix assign reset in malloc

(cherry picked from commit 1217d3fd47399a90a16341bcfa81f3c3482a1718)

- - - - -
24af3e6b by François Cartegnie at 2026-09-01T17:10:59+02:00
demux: ogg: fix potential unterminated string

(adapted from commit 82071bc7bb6c6df2068ce9b4db3e3b4b9f32ac70)

- - - - -
40415e74 by François Cartegnie at 2026-09-01T17:10:59+02:00
demux: ogg: use realloc_or_free

(cherry picked from commit fc57942afeab0b025b8de549ddefb9bc06064f55)

- - - - -
565d3934 by Jonas Dittrich at 2026-09-01T17:10:59+02:00
ogg: fix parsing skeleton packets with invalid granulepos

(adapted from commit 09491061fa6def4b6d694da7da332e619ee2fa9f)

- - - - -
3feffaa1 by François Cartegnie at 2026-09-01T17:10:59+02:00
demux: ogg: refactor streams configuration

(adapted from commit e115092edd5aecc738029b4628aeae5ad3d3ac01)

- - - - -


1 changed file:

- modules/demux/ogg.c


Changes:

=====================================
modules/demux/ogg.c
=====================================
@@ -35,6 +35,7 @@
 #include <vlc_demux.h>
 #include <vlc_meta.h>
 #include <vlc_input.h>
+#include <vlc_memory.h>
 
 #include <ogg/ogg.h>
 
@@ -129,6 +130,7 @@ static void Ogg_SendOrQueueBlocks( demux_t *, logical_stream_t *, block_t * );
 static void Ogg_CreateES( demux_t *p_demux );
 static int Ogg_BeginningOfStream( demux_t *p_demux );
 static int Ogg_FindLogicalStreams( demux_t *p_demux );
+static int Ogg_ConfigureStream( demux_t *p_demux, ogg_packet oggpacket, logical_stream_t * );
 static void Ogg_EndOfStream( demux_t *p_demux );
 
 /* */
@@ -1229,6 +1231,7 @@ static void Ogg_DecodePacket( demux_t *p_demux,
                               logical_stream_t *p_stream,
                               ogg_packet *p_oggpacket )
 {
+    demux_sys_t *p_sys = p_demux->p_sys;
     block_t *p_block;
     bool b_selected;
     int i_header_len = 0;
@@ -1257,6 +1260,10 @@ static void Ogg_DecodePacket( demux_t *p_demux,
         Ogg_ReadSkeletonIndex( p_demux, p_oggpacket );
         return;
     }
+    else if ( p_stream == p_sys->p_skelstream ) {
+        // skeleton streams do not have any data packets
+        return;
+    }
     else if( p_stream->fmt.i_codec == VLC_CODEC_VP8 &&
              p_oggpacket->bytes >= 7 &&
              !memcmp( p_oggpacket->packet, "OVP80\x02\x20", 7 ) )
@@ -1346,19 +1353,15 @@ static void Ogg_DecodePacket( demux_t *p_demux,
         if( !b_xiph && p_oggpacket->bytes > 0 &&
             (size_t)p_oggpacket->bytes < SIZE_MAX - p_stream->i_headers )
         {
-            uint8_t *p_realloc = realloc( p_stream->p_headers, p_stream->i_headers + p_oggpacket->bytes );
-            if( p_realloc )
+            p_stream->p_headers = realloc_or_free( p_stream->p_headers,
+                                                   p_stream->i_headers + p_oggpacket->bytes );
+            if( p_stream->p_headers )
             {
-                memcpy( &p_realloc[p_stream->i_headers], p_oggpacket->packet, p_oggpacket->bytes );
+                memcpy( &p_stream->p_headers[p_stream->i_headers], p_oggpacket->packet, p_oggpacket->bytes );
                 p_stream->i_headers += p_oggpacket->bytes;
-                p_stream->p_headers = p_realloc;
             }
             else
-            {
-                free( p_stream->p_headers );
                 p_stream->i_headers = 0;
-                p_stream->p_headers = NULL;
-            }
         }
         else if( b_xiph &&
                  xiph_AppendHeaders( &p_stream->i_headers, &p_stream->p_headers,
@@ -1375,11 +1378,13 @@ static void Ogg_DecodePacket( demux_t *p_demux,
                 /* Last header received, commit changes */
                 free( p_stream->fmt.p_extra );
 
-                p_stream->fmt.i_extra = p_stream->i_headers;
                 p_stream->fmt.p_extra = malloc( p_stream->i_headers );
                 if( p_stream->fmt.p_extra )
+                {
                     memcpy( p_stream->fmt.p_extra, p_stream->p_headers,
                             p_stream->i_headers );
+                    p_stream->fmt.i_extra = p_stream->i_headers;
+                }
                 else
                     p_stream->fmt.i_extra = 0;
 
@@ -1578,55 +1583,99 @@ static unsigned Ogg_OpusPacketDuration( ogg_packet *p_oggpacket )
  *
  * On success this function returns VLC_SUCCESS.
  ****************************************************************************/
-static int Ogg_FindLogicalStreams( demux_t *p_demux )
+static logical_stream_t *Ogg_FindLogicalStream( demux_t *p_demux, ogg_page *current_page )
 {
-    demux_sys_t *p_ogg = p_demux->p_sys  ;
-    ogg_packet oggpacket;
+    logical_stream_t *p_stream = calloc( 1, sizeof(logical_stream_t) );
+    if( unlikely( !p_stream ) )
+        return NULL;
 
-    p_ogg->i_total_bytes = stream_Size ( p_demux->s );
-    msg_Dbg( p_demux, "File length is %"PRId64" bytes", p_ogg->i_total_bytes );
+    es_format_Init( &p_stream->fmt, UNKNOWN_ES, 0 );
+    es_format_Init( &p_stream->fmt_old, UNKNOWN_ES, 0 );
+    p_stream->b_initializing = true;
 
+    /* Setup the logical stream */
+    p_stream->i_serial_no = ogg_page_serialno( current_page );
+    ogg_stream_init( &p_stream->os, p_stream->i_serial_no );
 
-    while( Ogg_ReadPage( p_demux, &p_ogg->current_page ) == VLC_SUCCESS )
+    /* Extract the initial header from the first page and verify
+             * the codec type of this Ogg bitstream */
+    if( ogg_stream_pagein( &p_stream->os, current_page ) < 0 )
     {
+        /* error. stream version mismatch perhaps */
+        msg_Err( p_demux, "error reading first page of "
+                          "Ogg bitstream data" );
+        goto failed;
+    }
 
-        if( ogg_page_bos( &p_ogg->current_page ) )
-        {
+    ogg_packet oggpacket;
+    if ( ogg_stream_packetpeek( &p_stream->os, &oggpacket ) != 1 )
+    {
+        msg_Err( p_demux, "error in ogg_stream_packetpeek" );
+        goto failed;
+    }
 
-            /* All is wonderful in our fine fine little world.
-             * We found the beginning of our first logical stream. */
-            while( ogg_page_bos( &p_ogg->current_page ) )
-            {
-                logical_stream_t *p_stream = calloc( 1, sizeof(logical_stream_t) );
-                if( unlikely( !p_stream ) )
-                    return VLC_ENOMEM;
+    if ( Ogg_ConfigureStream( p_demux, oggpacket, p_stream ) != VLC_SUCCESS )
+        goto failed;
 
-                TAB_APPEND( p_ogg->i_streams, p_ogg->pp_stream, p_stream );
+    /* we'll need to get all headers */
+    p_stream->b_initializing &= p_stream->b_force_backup;
 
-                es_format_Init( &p_stream->fmt, UNKNOWN_ES, 0 );
-                es_format_Init( &p_stream->fmt_old, UNKNOWN_ES, 0 );
-                p_stream->b_initializing = true;
+    return p_stream;
 
-                /* Setup the logical stream */
-                p_stream->i_serial_no = ogg_page_serialno( &p_ogg->current_page );
-                ogg_stream_init( &p_stream->os, p_stream->i_serial_no );
+failed:
+    Ogg_LogicalStreamDelete( p_demux, p_stream );
+    return NULL;
+}
 
-                /* Extract the initial header from the first page and verify
-                 * the codec type of this Ogg bitstream */
-                if( ogg_stream_pagein( &p_stream->os, &p_ogg->current_page ) < 0 )
-                {
-                    /* error. stream version mismatch perhaps */
-                    msg_Err( p_demux, "error reading first page of "
-                             "Ogg bitstream data" );
-                    return VLC_EGENERIC;
-                }
+static int Ogg_FindLogicalStreams( demux_t *p_demux )
+{
+    demux_sys_t *p_ogg = p_demux->p_sys;
+
+    p_ogg->i_total_bytes = stream_Size ( p_demux->s );
+    msg_Dbg( p_demux, "File length is %"PRId64" bytes", p_ogg->i_total_bytes );
 
-                if ( ogg_stream_packetpeek( &p_stream->os, &oggpacket ) != 1 )
+    while( Ogg_ReadPage( p_demux, &p_ogg->current_page ) == VLC_SUCCESS )
+    {
+        /* All is wonderful in our fine fine little world.
+         * We found the beginning of our first logical stream. */
+        if( !ogg_page_bos( &p_ogg->current_page ) )
+        {
+            /* This is the first data page, which means we are now finished
+             * with the initial pages. We just need to store it in the relevant
+             * bitstream. */
+            for( int i_stream = 0; i_stream < p_ogg->i_streams; i_stream++ )
+            {
+                if( ogg_stream_pagein( &p_ogg->pp_stream[i_stream]->os,
+                                       &p_ogg->current_page ) == 0 )
                 {
-                    msg_Err( p_demux, "error in ogg_stream_packetpeek" );
-                    return VLC_EGENERIC;
+                    p_ogg->b_page_waiting = true;
+                    break;
                 }
+            }
+            return p_ogg->i_streams ? VLC_SUCCESS : VLC_EGENERIC;
+        }
+
+        /* Try to configure the new stream */
+        logical_stream_t *p_stream = Ogg_FindLogicalStream( p_demux, &p_ogg->current_page );
+        if( unlikely( !p_stream ) )
+            continue;
+
+        TAB_APPEND( p_ogg->i_streams, p_ogg->pp_stream, p_stream );
+        /* we'll need to get all headers */
+        if ( p_stream )
+            p_stream->b_initializing &= p_stream->b_force_backup;
+    }
 
+    return VLC_EGENERIC;
+}
+
+static int Ogg_ConfigureStream( demux_t *p_demux, ogg_packet oggpacket, logical_stream_t *p_stream )
+{
+    demux_sys_t *p_ogg = p_demux->p_sys;
+
+    { // note: old indentation kept on purpose for rebases & blaming
+        {
+            {
                 /* Check for Vorbis header */
                 if( oggpacket.bytes >= 7 &&
                     ! memcmp( oggpacket.packet, "\x01vorbis", 7 ) )
@@ -1637,9 +1686,7 @@ static int Ogg_FindLogicalStreams( demux_t *p_demux )
                     else
                     {
                         msg_Dbg( p_demux, "found invalid vorbis header" );
-                        Ogg_LogicalStreamDelete( p_demux, p_stream );
-                        p_stream = NULL;
-                        p_ogg->i_streams--;
+                        return VLC_EGENERIC;
                     }
                 }
                 /* Check for Speex header */
@@ -1657,9 +1704,7 @@ static int Ogg_FindLogicalStreams( demux_t *p_demux )
                     else
                     {
                         msg_Dbg( p_demux, "found invalid Speex header" );
-                        Ogg_LogicalStreamDelete( p_demux, p_stream );
-                        p_stream = NULL;
-                        p_ogg->i_streams--;
+                        return VLC_EGENERIC;
                     }
                 }
                 /* Check for Opus header */
@@ -1712,9 +1757,7 @@ static int Ogg_FindLogicalStreams( demux_t *p_demux )
                     if ( !Ogg_ReadFlacStreamInfo( p_demux, p_stream, &oggpacket ) )
                     {
                         msg_Dbg( p_demux, "found invalid Flac header" );
-                        Ogg_LogicalStreamDelete( p_demux, p_stream );
-                        p_stream = NULL;
-                        p_ogg->i_streams--;
+                        return VLC_EGENERIC;
                     }
                 }
                 /* Check for Theora header */
@@ -1729,9 +1772,7 @@ static int Ogg_FindLogicalStreams( demux_t *p_demux )
                     else
                     {
                         msg_Dbg( p_demux, "found invalid Theora header" );
-                        Ogg_LogicalStreamDelete( p_demux, p_stream );
-                        p_stream = NULL;
-                        p_ogg->i_streams--;
+                        return VLC_EGENERIC;
                     }
                 }
                 /* Check for Daala header */
@@ -1746,9 +1787,7 @@ static int Ogg_FindLogicalStreams( demux_t *p_demux )
                     else
                     {
                         msg_Dbg( p_demux, "found invalid Daala header" );
-                        Ogg_LogicalStreamDelete( p_demux, p_stream );
-                        p_stream = NULL;
-                        p_ogg->i_streams--;
+                        return VLC_EGENERIC;
                     }
                 }
                 /* Check for Dirac header */
@@ -1763,9 +1802,7 @@ static int Ogg_FindLogicalStreams( demux_t *p_demux )
                     else
                     {
                         msg_Warn( p_demux, "found dirac header isn't decodable" );
-                        Ogg_LogicalStreamDelete( p_demux, p_stream );
-                        p_stream = NULL;
-                        p_ogg->i_streams--;
+                        return VLC_EGENERIC;
                     }
                 }
                 /* Check for Tarkin header */
@@ -1801,9 +1838,7 @@ static int Ogg_FindLogicalStreams( demux_t *p_demux )
                     else
                     {
                         msg_Dbg( p_demux, "invalid VP8 header found");
-                        Ogg_LogicalStreamDelete( p_demux, p_stream );
-                        p_stream = NULL;
-                        p_ogg->i_streams--;
+                        return VLC_EGENERIC;
                     }
                 }
                 /* Check for Annodex header */
@@ -1812,8 +1847,7 @@ static int Ogg_FindLogicalStreams( demux_t *p_demux )
                 {
                     Ogg_ReadAnnodexHeader( p_demux, p_stream, &oggpacket );
                     /* kill annodex track */
-                    FREENULL( p_stream );
-                    p_ogg->i_streams--;
+                    return VLC_EGENERIC;
                 }
                 /* Check for Annodex header */
                 else if( oggpacket.bytes >= 7 &&
@@ -1831,9 +1865,7 @@ static int Ogg_FindLogicalStreams( demux_t *p_demux )
                     else
                     {
                         msg_Dbg( p_demux, "invalid kate header found");
-                        Ogg_LogicalStreamDelete( p_demux, p_stream );
-                        p_stream = NULL;
-                        p_ogg->i_streams--;
+                        return VLC_EGENERIC;
                     }
                 }
                 /* Check for OggDS */
@@ -1883,6 +1915,11 @@ static int Ogg_FindLogicalStreams( demux_t *p_demux )
                                  p_stream->fmt.video.i_height,
                                  p_stream->fmt.video.i_bits_per_pixel);
 
+                        if ( !p_stream->fmt.video.i_frame_rate ||
+                             !p_stream->fmt.video.i_frame_rate_base )
+                        {
+                            return VLC_EGENERIC;
+                        }
                     }
                     /* Check for audio header (old format) */
                     else if( GetDWLE((oggpacket.packet+96)) == 0x05589F81 )
@@ -1895,13 +1932,13 @@ static int Ogg_FindLogicalStreams( demux_t *p_demux )
                         i_extra_size = GetWLE((oggpacket.packet+140));
                         if( i_extra_size > 0 && i_extra_size < oggpacket.bytes - 142 )
                         {
-                            p_stream->fmt.i_extra = i_extra_size;
                             p_stream->fmt.p_extra = malloc( i_extra_size );
                             if( p_stream->fmt.p_extra )
+                            {
                                 memcpy( p_stream->fmt.p_extra,
                                         oggpacket.packet + 142, i_extra_size );
-                            else
-                                p_stream->fmt.i_extra = 0;
+                                p_stream->fmt.i_extra = i_extra_size;
+                            }
                         }
 
                         i_format_tag = GetWLE((oggpacket.packet+124));
@@ -1939,17 +1976,14 @@ static int Ogg_FindLogicalStreams( demux_t *p_demux )
                         if ( p_stream->f_rate == 0 )
                         {
                             msg_Dbg( p_demux, "invalid oggds audio header" );
-                            Ogg_LogicalStreamDelete( p_demux, p_stream );
-                            p_stream = NULL;
-                            p_ogg->i_streams--;
+                            return VLC_EGENERIC;
                         }
                     }
                     else
                     {
                         msg_Dbg( p_demux, "stream %d has an old header "
-                            "but is of an unknown type", p_ogg->i_streams-1 );
-                        FREENULL( p_stream );
-                        p_ogg->i_streams--;
+                            "but is of an unknown type", p_ogg->i_streams );
+                        return VLC_EGENERIC;
                     }
                 }
                 /* Check for OggDS */
@@ -2031,13 +2065,12 @@ static int Ogg_FindLogicalStreams( demux_t *p_demux )
                         if( i_extra_size > 0 &&
                             i_extra_size < oggpacket.bytes - 1 - 56 )
                         {
-                            p_stream->fmt.i_extra = i_extra_size;
-                            p_stream->fmt.p_extra = malloc( p_stream->fmt.i_extra );
+                            p_stream->fmt.p_extra = malloc( i_extra_size );
                             if( p_stream->fmt.p_extra )
-                                memcpy( p_stream->fmt.p_extra, oggpacket.packet + 57,
-                                        p_stream->fmt.i_extra );
-                            else
-                                p_stream->fmt.i_extra = 0;
+                            {
+                                memcpy( p_stream->fmt.p_extra, oggpacket.packet + 57, i_extra_size );
+                                p_stream->fmt.i_extra = i_extra_size;
+                            }
                         }
 
                         memcpy( p_buffer, st->subtype, 4 );
@@ -2074,9 +2107,7 @@ static int Ogg_FindLogicalStreams( demux_t *p_demux )
                         if ( p_stream->f_rate == 0 )
                         {
                             msg_Dbg( p_demux, "invalid oggds audio header" );
-                            Ogg_LogicalStreamDelete( p_demux, p_stream );
-                            p_stream = NULL;
-                            p_ogg->i_streams--;
+                            return VLC_EGENERIC;
                         }
                     }
                     /* Check for text (subtitles) header */
@@ -2092,9 +2123,8 @@ static int Ogg_FindLogicalStreams( demux_t *p_demux )
                     else
                     {
                         msg_Dbg( p_demux, "stream %d has a header marker "
-                            "but is of an unknown type", p_ogg->i_streams-1 );
-                        FREENULL( p_stream );
-                        p_ogg->i_streams--;
+                            "but is of an unknown type", p_ogg->i_streams );
+                        return VLC_EGENERIC;
                     }
                 }
                 else if( oggpacket.bytes >= 8 &&
@@ -2103,7 +2133,7 @@ static int Ogg_FindLogicalStreams( demux_t *p_demux )
                 {
                     /* Skeleton */
                     msg_Dbg( p_demux, "stream %d is a skeleton",
-                                p_ogg->i_streams-1 );
+                                p_ogg->i_streams );
                     Ogg_ReadSkeletonHeader( p_demux, p_stream, &oggpacket );
                 }
                 /* Check for OggSpots header */
@@ -2117,35 +2147,14 @@ static int Ogg_FindLogicalStreams( demux_t *p_demux )
                     else
                     {
                         msg_Err( p_demux, "found invalid OggSpots header" );
-                        Ogg_LogicalStreamDelete( p_demux, p_stream );
-                        p_stream = NULL;
-                        p_ogg->i_streams--;
+                        return VLC_EGENERIC;
                     }
                 }
                 else
                 {
                     msg_Dbg( p_demux, "stream %d is of unknown type",
-                             p_ogg->i_streams-1 );
-                }
-
-                /* we'll need to get all headers */
-                if ( p_stream )
-                    p_stream->b_initializing &= p_stream->b_force_backup;
-
-                if( Ogg_ReadPage( p_demux, &p_ogg->current_page ) != VLC_SUCCESS )
+                             p_ogg->i_streams );
                     return VLC_EGENERIC;
-            }
-
-            /* This is the first data page, which means we are now finished
-             * with the initial pages. We just need to store it in the relevant
-             * bitstream. */
-            for( int i_stream = 0; i_stream < p_ogg->i_streams; i_stream++ )
-            {
-                if( ogg_stream_pagein( &p_ogg->pp_stream[i_stream]->os,
-                                       &p_ogg->current_page ) == 0 )
-                {
-                    p_ogg->b_page_waiting = true;
-                    break;
                 }
             }
 
@@ -3010,77 +3019,81 @@ static bool Ogg_ReadVP8Header( demux_t *p_demux, logical_stream_t *p_stream,
     }
 }
 
-static void Ogg_ApplyContentType( logical_stream_t *p_stream, const char* psz_value,
+#define CMPVALUE(str) \
+    (bytes >= (sizeof(str)-1) && !strncmp((const char *)p_value, str, sizeof(str)-1))
+
+static void Ogg_ApplyContentType( logical_stream_t *p_stream,
+                                  const uint8_t *p_value, size_t bytes,
                                   bool *b_force_backup, bool *b_packet_out )
 {
-    if( p_stream->fmt.i_cat != UNKNOWN_ES )
+    if( p_stream->fmt.i_cat != UNKNOWN_ES || bytes == 0 )
         return;
 
-    if( !strncmp(psz_value, "audio/x-wav", 11) )
+    if( CMPVALUE("audio/x-wav") )
     {
         /* n.b. WAVs are unsupported right now */
         es_format_Change( &p_stream->fmt, UNKNOWN_ES, 0 );
         free( p_stream->fmt.psz_description );
         p_stream->fmt.psz_description = strdup("WAV Audio (Unsupported)");
     }
-    else if( !strncmp(psz_value, "audio/x-vorbis", 14) ||
-             !strncmp(psz_value, "audio/vorbis", 12) )
+    else if( CMPVALUE("audio/x-vorbis") ||
+             CMPVALUE("audio/vorbis") )
     {
         es_format_Change( &p_stream->fmt, AUDIO_ES, VLC_CODEC_VORBIS );
 
         *b_force_backup = true;
     }
-    else if( !strncmp(psz_value, "audio/x-speex", 13) ||
-             !strncmp(psz_value, "audio/speex", 11) )
+    else if( CMPVALUE("audio/x-speex") ||
+             CMPVALUE("audio/speex") )
     {
         es_format_Change( &p_stream->fmt, AUDIO_ES, VLC_CODEC_SPEEX );
 
         *b_force_backup = true;
     }
-    else if( !strncmp(psz_value, "audio/flac", 10) )
+    else if( CMPVALUE("audio/flac") )
     {
         es_format_Change( &p_stream->fmt, AUDIO_ES, VLC_CODEC_FLAC );
 
         *b_force_backup = true;
     }
-    else if( !strncmp(psz_value, "video/x-theora", 14) ||
-             !strncmp(psz_value, "video/theora", 12) )
+    else if( CMPVALUE("video/x-theora") ||
+             CMPVALUE("video/theora") )
     {
         es_format_Change( &p_stream->fmt, VIDEO_ES, VLC_CODEC_THEORA );
 
         *b_force_backup = true;
     }
-    else if( !strncmp(psz_value, "video/x-daala", 13) ||
-             !strncmp(psz_value, "video/daala", 11) )
+    else if( CMPVALUE("video/x-daala") ||
+             CMPVALUE("video/daala") )
     {
         es_format_Change( &p_stream->fmt, VIDEO_ES, VLC_CODEC_DAALA );
 
         *b_force_backup = true;
     }
-    else if( !strncmp(psz_value, "video/x-xvid", 12) )
+    else if( CMPVALUE("video/x-xvid") )
     {
         es_format_Change( &p_stream->fmt, VIDEO_ES, VLC_FOURCC( 'x','v','i','d' ) );
 
         *b_force_backup = true;
     }
-    else if( !strncmp(psz_value, "video/mpeg", 10) )
+    else if( CMPVALUE("video/mpeg") )
     {
         /* n.b. MPEG streams are unsupported right now */
         es_format_Change( &p_stream->fmt, VIDEO_ES, VLC_CODEC_MPGV );
     }
-    else if( !strncmp(psz_value, "text/x-cmml", 11) ||
-             !strncmp(psz_value, "text/cmml", 9) )
+    else if( CMPVALUE("text/x-cmml") ||
+             CMPVALUE("text/cmml") )
     {
         es_format_Change( &p_stream->fmt, SPU_ES, VLC_CODEC_CMML );
         *b_packet_out = true;
     }
-    else if( !strncmp(psz_value, "application/kate", 16) )
+    else if( CMPVALUE("application/kate") )
     {
         /* ??? */
         es_format_Change( &p_stream->fmt, UNKNOWN_ES, 0 );
         p_stream->fmt.psz_description = strdup("OGG Kate Overlay (Unsupported)");
     }
-    else if( !strncmp(psz_value, "video/x-vp8", 11) )
+    else if( CMPVALUE("video/x-vp8") )
     {
         es_format_Change( &p_stream->fmt, VIDEO_ES, VLC_CODEC_VP8 );
     }
@@ -3119,7 +3132,6 @@ static void Ogg_ReadAnnodexHeader( demux_t *p_demux,
     {
         uint64_t granule_rate_numerator;
         uint64_t granule_rate_denominator;
-        char content_type_string[1024];
 
         /* Read in Annodex header fields */
 
@@ -3130,28 +3142,26 @@ static void Ogg_ReadAnnodexHeader( demux_t *p_demux,
 
         /* we are guaranteed that the first header field will be
          * the content-type (by the Annodex standard) */
-        content_type_string[0] = '\0';
+        long value_size = 0;
         if( !strncasecmp( (char*)(&p_oggpacket->packet[28]), "Content-Type: ", 14 ) )
         {
             uint8_t *p = memchr( &p_oggpacket->packet[42], '\r',
-                                 p_oggpacket->bytes - 42 );
-            if( p && p[0] == '\r' && p[1] == '\n' )
-                sscanf( (char*)(&p_oggpacket->packet[42]), "%1023s\r\n",
-                        content_type_string );
+                                 p_oggpacket->bytes - 1 );
+            value_size = p ? p - &p_oggpacket->packet[42] : p_oggpacket->bytes - 42;
         }
 
+        char debug_string[32] = {0};
+        strncpy(debug_string, &p_oggpacket->packet[42], __MIN(value_size, 31));
         msg_Dbg( p_demux, "AnxData packet info: %"PRId64" / %"PRId64", %d, ``%s''",
                  granule_rate_numerator, granule_rate_denominator,
-                 p_stream->i_secondary_header_packets, content_type_string );
+                 p_stream->i_secondary_header_packets, debug_string );
 
         p_stream->f_rate = (float) granule_rate_numerator /
             (float) granule_rate_denominator;
 
-        /* What type of file do we have?
-         * strcmp is safe to use here because we've extracted
-         * content_type_string from the stream manually */
+        /* What type of file do we have? */
         bool b_dopacketout = false;
-        Ogg_ApplyContentType( p_stream, content_type_string,
+        Ogg_ApplyContentType( p_stream, &p_oggpacket->packet[42], value_size,
                               &p_stream->b_force_backup, &b_dopacketout );
         if ( b_dopacketout ) ogg_stream_packetout( &p_stream->os, p_oggpacket );
     }
@@ -3321,7 +3331,9 @@ static void Ogg_ApplySkeleton( logical_stream_t *p_stream )
         else if ( ! strncmp("Content-Type: ", psz_message, 14 ) )
         {
             bool b_foo;
-            Ogg_ApplyContentType( p_stream, psz_message + 14, &b_foo, &b_foo );
+            psz_message += 14;
+            Ogg_ApplyContentType( p_stream, (const uint8_t *)psz_message,
+                                  strlen(psz_message), &b_foo,  &b_foo );
         }
     }
 }



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/121970d092572372324465305d6b73ce977dff7b...3feffaa1228e5442e51a0cc46105bc093a888c42

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/121970d092572372324465305d6b73ce977dff7b...3feffaa1228e5442e51a0cc46105bc093a888c42
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help




More information about the vlc-commits mailing list