[vlc-commits] [Git][videolan/vlc][master] 6 commits: demux: ogg: refactor streams configuration

François Cartegnie (@fcartegnie) gitlab at videolan.org
Fri Apr 24 06:26:33 UTC 2026



François Cartegnie pushed to branch master at VideoLAN / VLC


Commits:
e115092e by François Cartegnie at 2026-04-24T08:09:58+02:00
demux: ogg: refactor streams configuration

- - - - -
1217d3fd by François Cartegnie at 2026-04-24T08:09:58+02:00
demux: ogg: fix assign reset in malloc

- - - - -
82071bc7 by François Cartegnie at 2026-04-24T08:09:58+02:00
demux: ogg: fix potential unterminated string

- - - - -
fc57942a by François Cartegnie at 2026-04-24T08:09:58+02:00
demux: ogg: use realloc_or_free

- - - - -
c36963b7 by François Cartegnie at 2026-04-24T08:09:58+02:00
demux: ogg: fix headers appending test

- - - - -
98af112d by François Cartegnie at 2026-04-24T08:09:58+02:00
demux: ogg: check header realloc for overflow

- - - - -


1 changed file:

- modules/demux/ogg.c


Changes:

=====================================
modules/demux/ogg.c
=====================================
@@ -146,6 +146,7 @@ static inline bool Ogg_HasQueuedBlocks( const logical_stream_t *p_stream )
 static void Ogg_CreateES( demux_t *p_demux, bool );
 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 );
 
 /* */
@@ -1394,23 +1395,21 @@ static void Ogg_DecodePacket( demux_t *p_demux,
         }
 
         /* Backup the ogg packet (likely an header packet) */
-        if( !b_xiph && (p_stream->i_headers + p_oggpacket->bytes) )
+        if( !b_xiph && p_oggpacket->bytes &&
+            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( xiph_AppendHeaders( &p_stream->i_headers, &p_stream->p_headers,
+        else if( b_xiph &&
+                 xiph_AppendHeaders( &p_stream->i_headers, &p_stream->p_headers,
                                      p_oggpacket->bytes, p_oggpacket->packet ) )
         {
             free(p_stream->p_headers);
@@ -1424,11 +1423,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;
 
@@ -1606,58 +1607,102 @@ 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 = malloc( 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 );
+    Ogg_LogicalStreamInit( p_stream );
 
+    /* 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 )
+    if( ogg_page_granulepos( current_page ) == 0 && !p_stream->b_oggds )
+        p_stream->page_type = OGGPAGE_HEADER;
+    else
+        p_stream->page_type = OGGPAGE_OTHER;
+
+    /* 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 = malloc( sizeof(logical_stream_t) );
-                if( unlikely( !p_stream ) )
-                    return VLC_ENOMEM;
+    if ( Ogg_ConfigureStream( p_demux, oggpacket, p_stream ) != VLC_SUCCESS )
+        goto failed;
 
-                Ogg_LogicalStreamInit( p_stream );
+    /* we'll need to get all headers */
+    p_stream->b_initializing &= p_stream->b_force_backup;
 
-                /* 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 );
+    return p_stream;
 
-                if( ogg_page_granulepos( &p_ogg->current_page ) == 0 && !p_stream->b_oggds )
-                    p_stream->page_type = OGGPAGE_HEADER;
-                else
-                    p_stream->page_type = OGGPAGE_OTHER;
+failed:
+    Ogg_LogicalStreamDelete( p_demux, p_stream );
+    return NULL;
+}
 
-                TAB_APPEND( p_ogg->i_streams, p_ogg->pp_stream, p_stream );
+static int Ogg_FindLogicalStreams( demux_t *p_demux )
+{
+    demux_sys_t *p_ogg = p_demux->p_sys;
 
-                /* 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;
-                }
+    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;
                 }
+            }
+            break;
+        }
 
+        /* 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 p_ogg->i_streams ? VLC_SUCCESS : 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 ) )
@@ -1668,10 +1713,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;
-                        TAB_ERASE( p_ogg->i_streams, p_ogg->pp_stream,
-                                   p_ogg->i_streams - 1 );
+                        return VLC_EGENERIC;
                     }
                 }
                 /* Check for Speex header */
@@ -1690,10 +1732,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;
-                        TAB_ERASE( p_ogg->i_streams, p_ogg->pp_stream,
-                                   p_ogg->i_streams - 1 );
+                        return VLC_EGENERIC;
                     }
                 }
                 /* Check for Opus header */
@@ -1746,10 +1785,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;
-                        TAB_ERASE( p_ogg->i_streams, p_ogg->pp_stream,
-                                   p_ogg->i_streams - 1 );
+                        return VLC_EGENERIC;
                     }
                 }
                 /* Check for Theora header */
@@ -1765,10 +1801,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;
-                        TAB_ERASE( p_ogg->i_streams, p_ogg->pp_stream,
-                                   p_ogg->i_streams - 1 );
+                        return VLC_EGENERIC;
                     }
                 }
                 /* Check for Daala header */
@@ -1784,10 +1817,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;
-                        TAB_ERASE( p_ogg->i_streams, p_ogg->pp_stream,
-                                   p_ogg->i_streams - 1 );
+                        return VLC_EGENERIC;
                     }
                 }
                 /* Check for Dirac header */
@@ -1802,10 +1832,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;
-                        TAB_ERASE( p_ogg->i_streams, p_ogg->pp_stream,
-                                   p_ogg->i_streams - 1 );
+                        return VLC_EGENERIC;
                     }
                 }
                 /* Check for VP8 header */
@@ -1822,10 +1849,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;
-                        TAB_ERASE( p_ogg->i_streams, p_ogg->pp_stream,
-                                   p_ogg->i_streams - 1 );
+                        return VLC_EGENERIC;
                     }
                 }
                 /* Check for Annodex header */
@@ -1834,9 +1858,7 @@ static int Ogg_FindLogicalStreams( demux_t *p_demux )
                 {
                     Ogg_ReadAnnodexHeader( p_demux, p_stream, &oggpacket );
                     /* kill annodex track */
-                    FREENULL( p_stream );
-                    TAB_ERASE( p_ogg->i_streams, p_ogg->pp_stream,
-                               p_ogg->i_streams - 1 );
+                    return VLC_EGENERIC;
                 }
                 /* Check for Annodex header */
                 else if( oggpacket.bytes >= 7 &&
@@ -1854,10 +1876,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;
-                        TAB_ERASE( p_ogg->i_streams, p_ogg->pp_stream,
-                                   p_ogg->i_streams - 1 );
+                        return VLC_EGENERIC;
                     }
                 }
                 /* Check for OggDS */
@@ -1910,10 +1929,7 @@ static int Ogg_FindLogicalStreams( demux_t *p_demux )
                         if ( !p_stream->fmt.video.i_frame_rate ||
                              !p_stream->fmt.video.i_frame_rate_base )
                         {
-                            Ogg_LogicalStreamDelete( p_demux, p_stream );
-                            p_stream = NULL;
-                            TAB_ERASE( p_ogg->i_streams, p_ogg->pp_stream,
-                                       p_ogg->i_streams - 1 );
+                            return VLC_EGENERIC;
                         }
                     }
                     /* Check for audio header (old format) */
@@ -1927,13 +1943,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));
@@ -1974,19 +1990,14 @@ static int Ogg_FindLogicalStreams( demux_t *p_demux )
                         if ( p_stream->fmt.audio.i_rate == 0 )
                         {
                             msg_Dbg( p_demux, "invalid oggds audio header" );
-                            Ogg_LogicalStreamDelete( p_demux, p_stream );
-                            p_stream = NULL;
-                            TAB_ERASE( p_ogg->i_streams, p_ogg->pp_stream,
-                                       p_ogg->i_streams - 1 );
+                            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 );
-                        TAB_ERASE( p_ogg->i_streams, p_ogg->pp_stream,
-                                   p_ogg->i_streams - 1 );
+                        return VLC_EGENERIC;
                     }
                 }
                 /* Check for OggDS */
@@ -2074,13 +2085,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 );
@@ -2122,10 +2132,7 @@ static int Ogg_FindLogicalStreams( demux_t *p_demux )
                         if ( p_stream->fmt.audio.i_rate == 0 )
                         {
                             msg_Dbg( p_demux, "invalid oggds audio header" );
-                            Ogg_LogicalStreamDelete( p_demux, p_stream );
-                            p_stream = NULL;
-                            TAB_ERASE( p_ogg->i_streams, p_ogg->pp_stream,
-                                       p_ogg->i_streams - 1 );
+                            return VLC_EGENERIC;
                         }
                     }
                     /* Check for text (subtitles) header */
@@ -2142,9 +2149,7 @@ static int Ogg_FindLogicalStreams( demux_t *p_demux )
                     {
                         msg_Dbg( p_demux, "stream %d has a header marker "
                             "but is of an unknown type", p_ogg->i_streams-1 );
-                        FREENULL( p_stream );
-                        TAB_ERASE( p_ogg->i_streams, p_ogg->pp_stream,
-                                   p_ogg->i_streams - 1 );
+                        return VLC_EGENERIC;
                     }
                 }
                 else if( oggpacket.bytes >= 8 &&
@@ -2168,40 +2173,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;
-                        TAB_ERASE( p_ogg->i_streams, p_ogg->pp_stream,
-                                   p_ogg->i_streams - 1 );
+                        return VLC_EGENERIC;
                     }
                 }
                 else
                 {
-                    Ogg_LogicalStreamDelete( p_demux, p_stream );
-                    p_stream = NULL;
-                    TAB_ERASE( p_ogg->i_streams, p_ogg->pp_stream,
-                               p_ogg->i_streams - 1 );
                     msg_Dbg( p_demux, "stream %d is of unknown type",
                              p_ogg->i_streams );
-                }
-
-                /* 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 )
                     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;
                 }
             }
 
@@ -3103,71 +3082,75 @@ 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 )
 {
-    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, "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 );
     }
@@ -3206,7 +3189,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 */
 
@@ -3217,27 +3199,25 @@ 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 - 1 );
-            if( p && p[0] == '\r' && p[1] == '\n' )
-                sscanf( (char*)(&p_oggpacket->packet[42]), "%1023s\r\n",
-                        content_type_string );
+            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 );
 
         if( granule_rate_numerator && granule_rate_denominator )
             date_Init( &p_stream->dts, granule_rate_numerator, 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 */
-        Ogg_ApplyContentType( p_stream, content_type_string,
+        /* What type of file do we have? */
+        Ogg_ApplyContentType( p_stream, &p_oggpacket->packet[42], value_size,
                               &p_stream->b_force_backup );
     }
 }
@@ -3407,7 +3387,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 );
+            psz_message += 14;
+            Ogg_ApplyContentType( p_stream, (const uint8_t *)psz_message,
+                                  strlen(psz_message), &b_foo );
         }
     }
 }



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/fd0fbaeb77101577d3bc383f7f0282fbb347db31...98af112d53d74ed6c25eb67036e8291f1805285b

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/fd0fbaeb77101577d3bc383f7f0282fbb347db31...98af112d53d74ed6c25eb67036e8291f1805285b
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list