diff --git a/libavcodec/flac.c b/libavcodec/flac.c index 069cde442b..5ffbf93190 100644 --- a/libavcodec/flac.c +++ b/libavcodec/flac.c @@ -201,7 +201,7 @@ void ff_flac_set_channel_layout(AVCodecContext *avctx) avctx->channel_layout = 0; } -void ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s, +int ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s, const uint8_t *buffer) { GetBitContext gb; @@ -213,6 +213,7 @@ void ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s, av_log(avctx, AV_LOG_WARNING, "invalid max blocksize: %d\n", s->max_blocksize); s->max_blocksize = 16; + return AVERROR_INVALIDDATA; } skip_bits(&gb, 24); /* skip min frame size */ @@ -225,6 +226,7 @@ void ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s, if (s->bps < 4) { av_log(avctx, AV_LOG_ERROR, "invalid bps: %d\n", s->bps); s->bps = 16; + return AVERROR_INVALIDDATA; } avctx->channels = s->channels; @@ -239,4 +241,6 @@ void ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s, skip_bits_long(&gb, 64); /* md5 sum */ skip_bits_long(&gb, 64); /* md5 sum */ + + return 0; } diff --git a/libavcodec/flac.h b/libavcodec/flac.h index 96d971c9d7..991ab43f3c 100644 --- a/libavcodec/flac.h +++ b/libavcodec/flac.h @@ -95,8 +95,10 @@ typedef struct FLACFrameInfo { * @param[out] avctx codec context to set basic stream parameters * @param[out] s where parsed information is stored * @param[in] buffer pointer to start of 34-byte streaminfo data + * + * @return negative error code on faiure or >= 0 on success */ -void ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s, +int ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s, const uint8_t *buffer); /** diff --git a/libavcodec/flacdec.c b/libavcodec/flacdec.c index 5f5802c97f..d1beb4e15e 100644 --- a/libavcodec/flacdec.c +++ b/libavcodec/flacdec.c @@ -109,7 +109,9 @@ static av_cold int flac_decode_init(AVCodecContext *avctx) return AVERROR_INVALIDDATA; /* initialize based on the demuxer-supplied streamdata header */ - ff_flac_parse_streaminfo(avctx, &s->flac_stream_info, streaminfo); + ret = ff_flac_parse_streaminfo(avctx, &s->flac_stream_info, streaminfo); + if (ret < 0) + return ret; ret = allocate_buffers(s); if (ret < 0) return ret; @@ -175,7 +177,9 @@ static int parse_streaminfo(FLACContext *s, const uint8_t *buf, int buf_size) metadata_size != FLAC_STREAMINFO_SIZE) { return AVERROR_INVALIDDATA; } - ff_flac_parse_streaminfo(s->avctx, &s->flac_stream_info, &buf[8]); + ret = ff_flac_parse_streaminfo(s->avctx, &s->flac_stream_info, &buf[8]); + if (ret < 0) + return ret; ret = allocate_buffers(s); if (ret < 0) return ret;