diff options
author | Hendrik Leppkes <h.leppkes@gmail.com> | 2016-01-01 16:47:27 +0100 |
---|---|---|
committer | Hendrik Leppkes <h.leppkes@gmail.com> | 2016-01-01 16:47:27 +0100 |
commit | 1e96b151fa6e9931c626283b7dfc15e4ec0095aa (patch) | |
tree | d446814f822f9a3125c1b60414e1f9c68b6bdb64 /libavcodec | |
parent | 15c60c8af2271cd7d5c6c6ce7f8f127a32f18cfd (diff) | |
parent | 955aec3c7c7be39b659197e1ec379a09f2b7c41c (diff) | |
download | ffmpeg-1e96b151fa6e9931c626283b7dfc15e4ec0095aa.tar.gz |
Merge commit '955aec3c7c7be39b659197e1ec379a09f2b7c41c'
* commit '955aec3c7c7be39b659197e1ec379a09f2b7c41c':
mpegaudiodecheader: check the header in avpriv_mpegaudio_decode_header
Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/libmp3lame.c | 7 | ||||
-rw-r--r-- | libavcodec/mpegaudiodec_template.c | 19 | ||||
-rw-r--r-- | libavcodec/mpegaudiodecheader.c | 9 |
3 files changed, 18 insertions, 17 deletions
diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c index 873b390c0c..5642264a4a 100644 --- a/libavcodec/libmp3lame.c +++ b/libavcodec/libmp3lame.c @@ -246,11 +246,12 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, if (s->buffer_index < 4) return 0; h = AV_RB32(s->buffer); - if (ff_mpa_check_header(h) < 0) { + + ret = avpriv_mpegaudio_decode_header(&hdr, h); + if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "Invalid mp3 header at start of buffer\n"); return AVERROR_BUG; - } - if (avpriv_mpegaudio_decode_header(&hdr, h)) { + } else if (ret) { av_log(avctx, AV_LOG_ERROR, "free format output not supported\n"); return -1; } diff --git a/libavcodec/mpegaudiodec_template.c b/libavcodec/mpegaudiodec_template.c index f681ef7a57..d2420c1386 100644 --- a/libavcodec/mpegaudiodec_template.c +++ b/libavcodec/mpegaudiodec_template.c @@ -1672,12 +1672,11 @@ static int decode_frame(AVCodecContext * avctx, void *data, int *got_frame_ptr, av_log(avctx, AV_LOG_DEBUG, "discarding ID3 tag\n"); return buf_size; } - if (ff_mpa_check_header(header) < 0) { + ret = avpriv_mpegaudio_decode_header((MPADecodeHeader *)s, header); + if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "Header missing\n"); return AVERROR_INVALIDDATA; - } - - if (avpriv_mpegaudio_decode_header((MPADecodeHeader *)s, header) == 1) { + } else if (ret == 1) { /* free format: prepare to compute frame size */ s->frame_size = -1; return AVERROR_INVALIDDATA; @@ -1758,12 +1757,11 @@ static int decode_frame_adu(AVCodecContext *avctx, void *data, // Get header and restore sync word header = AV_RB32(buf) | 0xffe00000; - if (ff_mpa_check_header(header) < 0) { // Bad header, discard frame + ret = avpriv_mpegaudio_decode_header((MPADecodeHeader *)s, header); + if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "Invalid frame header\n"); - return AVERROR_INVALIDDATA; + return ret; } - - avpriv_mpegaudio_decode_header((MPADecodeHeader *)s, header); /* update codec info */ avctx->sample_rate = s->sample_rate; avctx->channels = s->nb_channels; @@ -1954,13 +1952,12 @@ static int decode_frame_mp3on4(AVCodecContext *avctx, void *data, } header = (AV_RB32(buf) & 0x000fffff) | s->syncword; // patch header - if (ff_mpa_check_header(header) < 0) { + ret = avpriv_mpegaudio_decode_header((MPADecodeHeader *)m, header); + if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "Bad header, discard block\n"); return AVERROR_INVALIDDATA; } - avpriv_mpegaudio_decode_header((MPADecodeHeader *)m, header); - if (ch + m->nb_channels > avctx->channels || s->coff[fr] + m->nb_channels > avctx->channels) { av_log(avctx, AV_LOG_ERROR, "frame channel count exceeds codec " diff --git a/libavcodec/mpegaudiodecheader.c b/libavcodec/mpegaudiodecheader.c index d522c064ac..30033fb2a2 100644 --- a/libavcodec/mpegaudiodecheader.c +++ b/libavcodec/mpegaudiodecheader.c @@ -37,6 +37,12 @@ int avpriv_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header) { int sample_rate, frame_size, mpeg25, padding; int sample_rate_index, bitrate_index; + int ret; + + ret = ff_mpa_check_header(header); + if (ret < 0) + return ret; + if (header & (1<<20)) { s->lsf = (header & (1<<19)) ? 0 : 1; mpeg25 = 0; @@ -117,9 +123,6 @@ int avpriv_mpa_decode_header2(uint32_t head, int *sample_rate, int *channels, in { MPADecodeHeader s1, *s = &s1; - if (ff_mpa_check_header(head) != 0) - return -1; - if (avpriv_mpegaudio_decode_header(s, head) != 0) { return -1; } |