[vlc-devel] [PATCH] avcodec: reconstruct the ALAC atom if we have enough data

Steve Lhomme robux4 at videolabs.io
Fri Feb 12 16:28:40 CET 2016


fixes #16620
---
 modules/codec/avcodec/audio.c | 37 ++++++++++++++++++++++++++++++-------
 1 file changed, 30 insertions(+), 7 deletions(-)

diff --git a/modules/codec/avcodec/audio.c b/modules/codec/avcodec/audio.c
index 159dbf1..9ce190f 100644
--- a/modules/codec/avcodec/audio.c
+++ b/modules/codec/avcodec/audio.c
@@ -85,15 +85,38 @@ static void InitDecoderConfig( decoder_t *p_dec, AVCodecContext *p_context )
         if( p_dec->fmt_in.i_codec == VLC_CODEC_ALAC )
         {
             static const uint8_t p_pattern[] = { 0, 0, 0, 36, 'a', 'l', 'a', 'c' };
-            /* Find alac atom XXX it is a bit ugly */
-            for( i_offset = 0; i_offset < i_size - (int)sizeof(p_pattern); i_offset++ )
+            if( i_size >= 24 && i_size < 36)
             {
-                if( !memcmp( &p_src[i_offset], p_pattern, sizeof(p_pattern) ) )
-                    break;
-            }
-            i_size = __MIN( p_dec->fmt_in.i_extra - i_offset, 36 );
-            if( i_size < 36 )
+                p_context->extradata =
+                    av_malloc( 12 + i_size + FF_INPUT_BUFFER_PADDING_SIZE );
+                if( p_context->extradata )
+                {
+                    uint8_t *p_dst = p_context->extradata;
+
+                    i_size = 0;
+                    memcpy( &p_dst[i_size], &p_pattern[0], 8 );
+                    i_size += 8;
+                    memset( &p_dst[i_size], 0, 4 );
+                    i_size += 4;
+                    memcpy( &p_dst[i_size], &p_src[0], p_dec->fmt_in.i_extra );
+                    i_size += p_dec->fmt_in.i_extra;
+                    p_context->extradata_size = i_size;
+                    memset( &p_dst[i_size], 0, FF_INPUT_BUFFER_PADDING_SIZE );
+                }
                 i_size = 0;
+            }
+            else
+            {
+                /* Find alac atom XXX it is a bit ugly */
+                for( i_offset = 0; i_offset < i_size - (int)sizeof(p_pattern); i_offset++ )
+                {
+                    if( !memcmp( &p_src[i_offset], p_pattern, sizeof(p_pattern) ) )
+                        break;
+                }
+                i_size = __MIN( p_dec->fmt_in.i_extra - i_offset, 36 );
+                if( i_size < 36 )
+                    i_size = 0;
+            }
         }
 
         if( i_size > 0 )
-- 
2.7.0



More information about the vlc-devel mailing list