aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/adtsenc.c
diff options
context:
space:
mode:
authorAlex Converse <alex.converse@gmail.com>2011-11-28 00:48:53 -0800
committerAlex Converse <alex.converse@gmail.com>2011-11-28 11:22:40 -0800
commitac47e014bbaf5163871a8beb7522015e0bc27615 (patch)
tree4f9b6c59c991d607d756f50d41122622ae00a625 /libavformat/adtsenc.c
parenta27805189ba505834c74ec72edc5fddf18f5cfa9 (diff)
downloadffmpeg-ac47e014bbaf5163871a8beb7522015e0bc27615.tar.gz
adtsenc: Check frame size.
Inspired by work from: Michael Niedermayer <michaelni@gmx.at>. Signed-off-by: Alex Converse <alex.converse@gmail.com>
Diffstat (limited to 'libavformat/adtsenc.c')
-rw-r--r--libavformat/adtsenc.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/libavformat/adtsenc.c b/libavformat/adtsenc.c
index ce002fe4db..55fece5dd6 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;
@@ -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);