[FFmpeg-devel] [PATCH] parser: error out if the codec doesn't match

Michael Niedermayer michael at niedermayer.cc
Tue Jan 5 11:46:23 CET 2016


On Tue, Jan 05, 2016 at 12:44:40AM +0100, Andreas Cadhalpun wrote:
> Otherwise this can have some surprising effects (crashes), so let's
> better not allow it.
> 
> Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun at googlemail.com>
> ---
>  libavcodec/parser.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/libavcodec/parser.c b/libavcodec/parser.c
> index 2809158..1f38edb 100644
> --- a/libavcodec/parser.c
> +++ b/libavcodec/parser.c
> @@ -141,6 +141,17 @@ int av_parser_parse2(AVCodecParserContext *s, AVCodecContext *avctx,
>      int index, i;
>      uint8_t dummy_buf[AV_INPUT_BUFFER_PADDING_SIZE];
>  
> +    if (avctx->codec_id != s->parser->codec_ids[0] &&
> +        avctx->codec_id != s->parser->codec_ids[1] &&
> +        avctx->codec_id != s->parser->codec_ids[2] &&
> +        avctx->codec_id != s->parser->codec_ids[3] &&
> +        avctx->codec_id != s->parser->codec_ids[4]) {
> +        av_log(avctx, AV_LOG_ERROR,
> +               "The parser doesn't match the codec %s.\n",
> +               avcodec_get_name(avctx->codec_id));
> +        return buf_size;
> +    }

does it also work to check if a parser is set when the codec id
is changed ? as in below

(that would avoid doing 5 extra checks per packet)

--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -521,6 +521,9 @@ fail:

 static void force_codec_ids(AVFormatContext *s, AVStream *st)
 {
+    if (st->parser)
+        return;
+
     switch (st->codec->codec_type) {
     case AVMEDIA_TYPE_VIDEO:
         if (s->video_codec_id)


[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Rewriting code that is poorly written but fully understood is good.
Rewriting code that one doesnt understand is a sign that one is less smart
then the original author, trying to rewrite it will not make it better.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20160105/2b4d2b70/attachment.sig>


More information about the ffmpeg-devel mailing list