X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fadtsenc.c;h=18a055a1e5712ac79a1ddbb5f4c8f3fc718d8c1b;hb=9ba43e50efa2483fb3ca1e3f62a474db7dd3ac8d;hp=5387cc855b1d105cb66cf8229a0c6ededa98f98b;hpb=bd4ebbbbed47761df65dd574dce6d3c56d29e2e7;p=ffmpeg diff --git a/libavformat/adtsenc.c b/libavformat/adtsenc.c index 5387cc855b1..18a055a1e57 100644 --- a/libavformat/adtsenc.c +++ b/libavformat/adtsenc.c @@ -27,6 +27,8 @@ #include "avformat.h" #include "adts.h" +#define ADTS_MAX_FRAME_BYTES ((1 << 13) - 1) + int ff_adts_decode_extradata(AVFormatContext *s, ADTSContext *adts, uint8_t *buf, int size) { GetBitContext gb; @@ -35,7 +37,7 @@ int ff_adts_decode_extradata(AVFormatContext *s, ADTSContext *adts, uint8_t *buf int off; init_get_bits(&gb, buf, size * 8); - off = ff_mpeg4audio_get_config(&m4ac, buf, size); + off = avpriv_mpeg4audio_get_config(&m4ac, buf, size * 8, 1); if (off < 0) return off; skip_bits_long(&gb, off); @@ -67,7 +69,7 @@ int ff_adts_decode_extradata(AVFormatContext *s, ADTSContext *adts, uint8_t *buf init_put_bits(&pb, adts->pce_data, MAX_PCE_SIZE); put_bits(&pb, 3, 5); //ID_PCE - adts->pce_size = (ff_copy_pce_data(&pb, &gb) + 3) / 8; + adts->pce_size = (avpriv_copy_pce_data(&pb, &gb) + 3) / 8; flush_put_bits(&pb); } @@ -93,6 +95,13 @@ int ff_adts_write_frame_header(ADTSContext *ctx, { PutBitContext pb; + unsigned full_frame_size = (unsigned)ADTS_HEADER_SIZE + size + pce_size; + if (full_frame_size > ADTS_MAX_FRAME_BYTES) { + av_log(NULL, AV_LOG_ERROR, "ADTS frame size too large: %u (max %d)\n", + full_frame_size, ADTS_MAX_FRAME_BYTES); + return AVERROR_INVALIDDATA; + } + init_put_bits(&pb, buf, ADTS_HEADER_SIZE); /* adts_fixed_header */ @@ -110,7 +119,7 @@ int ff_adts_write_frame_header(ADTSContext *ctx, /* adts_variable_header */ put_bits(&pb, 1, 0); /* copyright_identification_bit */ put_bits(&pb, 1, 0); /* copyright_identification_start */ - put_bits(&pb, 13, ADTS_HEADER_SIZE + size + pce_size); /* aac_frame_length */ + put_bits(&pb, 13, full_frame_size); /* aac_frame_length */ put_bits(&pb, 11, 0x7ff); /* adts_buffer_fullness */ put_bits(&pb, 2, 0); /* number_of_raw_data_blocks_in_frame */ @@ -128,7 +137,10 @@ static int adts_write_packet(AVFormatContext *s, AVPacket *pkt) if (!pkt->size) return 0; if (adts->write_adts) { - ff_adts_write_frame_header(adts, buf, pkt->size, adts->pce_size); + int err = ff_adts_write_frame_header(adts, buf, pkt->size, + adts->pce_size); + if (err < 0) + return err; avio_write(pb, buf, ADTS_HEADER_SIZE); if (adts->pce_size) { avio_write(pb, adts->pce_data, adts->pce_size);