Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FFmpeg/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Ruggles <justin.ruggles@gmail.com>2014-06-22 21:19:36 +0400
committerLuca Barbato <lu_zero@gentoo.org>2014-06-26 14:37:16 +0400
commit46c477c2a14b04a63ab11d31003b48fab6146a96 (patch)
tree8776c78076853280068e6343188090a6b55551ad
parentfcbcc561e0fdc95a7dd48b92db53846726aec27e (diff)
Check mp3 header before calling avpriv_mpegaudio_decode_header().
As indicated in the function documentation, the header MUST be checked prior to calling it because no consistency check is done there. CC:libav-stable@libav.org (cherry picked from commit f2f2e7627f0c878d13275af5d166ec5932665e28) Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
-rw-r--r--libavcodec/libmp3lame.c8
-rw-r--r--libavformat/mp3enc.c17
2 files changed, 17 insertions, 8 deletions
diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c
index ee76ff8812..2fc080ff09 100644
--- a/libavcodec/libmp3lame.c
+++ b/libavcodec/libmp3lame.c
@@ -175,6 +175,7 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
MPADecodeHeader hdr;
int len, ret, ch;
int lame_result;
+ uint32_t h;
if (frame) {
switch (avctx->sample_fmt) {
@@ -230,7 +231,12 @@ static int mp3lame_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
determine the frame size. */
if (s->buffer_index < 4)
return 0;
- if (avpriv_mpegaudio_decode_header(&hdr, AV_RB32(s->buffer))) {
+ h = AV_RB32(s->buffer);
+ if (ff_mpa_check_header(h) < 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)) {
av_log(avctx, AV_LOG_ERROR, "free format output not supported\n");
return -1;
}
diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c
index 932625864f..476d7f71cb 100644
--- a/libavformat/mp3enc.c
+++ b/libavformat/mp3enc.c
@@ -252,13 +252,16 @@ static int mp3_write_audio_packet(AVFormatContext *s, AVPacket *pkt)
if (mp3->xing_offset && pkt->size >= 4) {
MPADecodeHeader c;
-
- avpriv_mpegaudio_decode_header(&c, AV_RB32(pkt->data));
-
- if (!mp3->initial_bitrate)
- mp3->initial_bitrate = c.bit_rate;
- if ((c.bit_rate == 0) || (mp3->initial_bitrate != c.bit_rate))
- mp3->has_variable_bitrate = 1;
+ uint32_t h;
+
+ h = AV_RB32(pkt->data);
+ if (ff_mpa_check_header(h) == 0) {
+ avpriv_mpegaudio_decode_header(&c, h);
+ if (!mp3->initial_bitrate)
+ mp3->initial_bitrate = c.bit_rate;
+ if ((c.bit_rate == 0) || (mp3->initial_bitrate != c.bit_rate))
+ mp3->has_variable_bitrate = 1;
+ }
mp3_xing_add_frame(mp3, pkt);
}