Commit 1e96b151 authored by Hendrik Leppkes's avatar Hendrik Leppkes

Merge commit '955aec3c'

* commit '955aec3c':
  mpegaudiodecheader: check the header in avpriv_mpegaudio_decode_header
Merged-by: 's avatarHendrik Leppkes <h.leppkes@gmail.com>
parents 15c60c8a 955aec3c
......@@ -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;
}
......
......@@ -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 "
......
......@@ -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;
}
......
......@@ -82,9 +82,6 @@ static int mp3_read_probe(AVProbeData *p)
for(; buf < end; buf= buf2+1) {
buf2 = buf;
if(ff_mpa_check_header(AV_RB32(buf2)))
continue;
for(frames = 0; buf2 < end; frames++) {
int dummy;
header = AV_RB32(buf2);
......@@ -302,14 +299,16 @@ static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream *st, int64_t base)
MPADecodeHeader c;
int vbrtag_size = 0;
MP3DecContext *mp3 = s->priv_data;
int ret;
ffio_init_checksum(s->pb, ff_crcA001_update, 0);
v = avio_rb32(s->pb);
if(ff_mpa_check_header(v) < 0)
return -1;
if (avpriv_mpegaudio_decode_header(&c, v) == 0)
ret = avpriv_mpegaudio_decode_header(&c, v);
if (ret < 0)
return ret;
else if (ret == 0)
vbrtag_size = c.frame_size;
if(c.layer != 3)
return -1;
......
......@@ -309,12 +309,13 @@ static int mp3_write_audio_packet(AVFormatContext *s, AVPacket *pkt)
if (pkt->data && pkt->size >= 4) {
MPADecodeHeader mpah;
int ret;
int av_unused base;
uint32_t h;
h = AV_RB32(pkt->data);
if (ff_mpa_check_header(h) == 0) {
avpriv_mpegaudio_decode_header(&mpah, h);
ret = avpriv_mpegaudio_decode_header(&mpah, h);
if (ret >= 0) {
if (!mp3->initial_bitrate)
mp3->initial_bitrate = mpah.bit_rate;
if ((mpah.bit_rate == 0) || (mp3->initial_bitrate != mpah.bit_rate))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment