diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2014-08-30 20:21:17 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2014-08-30 20:31:50 +0200 |
commit | 807b7388402eb53c2022428f17dfbeaf8312ba74 (patch) | |
tree | d418b2fd2b0ebcf44ad262f3bd2c3d53df892fbf | |
parent | a507fea70769533d2f666bcc63edc8d15b6784be (diff) | |
parent | addbaf134836aea4e14f73add8c6d753a1373257 (diff) | |
download | ffmpeg-807b7388402eb53c2022428f17dfbeaf8312ba74.tar.gz |
Merge commit 'addbaf134836aea4e14f73add8c6d753a1373257' into release/1.1
* commit 'addbaf134836aea4e14f73add8c6d753a1373257':
mpegts: Do not try to write a PMT larger than SECTION_SIZE
Conflicts:
libavformat/mpegtsenc.c
See: 694c3a13c9489c6e05f88486b489dd0746d114fc
Merged-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | libavformat/mpegtsenc.c | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index a4cc752d59..81316ce00e 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -263,7 +263,7 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) { MpegTSWrite *ts = s->priv_data; uint8_t data[SECTION_LENGTH], *q, *desc_length_ptr, *program_info_length_ptr; - int val, stream_type, i; + int val, stream_type, i, err = 0; q = data; put16(&q, 0xe000 | service->pcr_pid); @@ -281,6 +281,11 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) AVStream *st = s->streams[i]; MpegTSWriteStream *ts_st = st->priv_data; AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL,0); + + if (q - data > SECTION_LENGTH - 32) { + err = 1; + break; + } switch(st->codec->codec_id) { case AV_CODEC_ID_MPEG1VIDEO: case AV_CODEC_ID_MPEG2VIDEO: @@ -313,8 +318,6 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) break; } - if (q - data > sizeof(data) - 32) - return AVERROR(EINVAL); *q++ = stream_type; put16(&q, 0xe000 | ts_st->pid); @@ -347,7 +350,11 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) len_ptr = q++; *len_ptr = 0; - for (p = lang->value; next && *len_ptr < 255 / 4 * 4 && q - data < sizeof(data) - 4; p = next + 1) { + for (p = lang->value; next && *len_ptr < 255 / 4 * 4; p = next + 1) { + if (q - data > SECTION_LENGTH - 4) { + err = 1; + break; + } next = strchr(p, ','); if (strlen(p) != 3 && (!next || next != p + 3)) continue; /* not a 3-letter code */ @@ -382,6 +389,11 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) *q++ = language[1]; *q++ = language[2]; *q++ = 0x10; /* normal subtitles (0x20 = if hearing pb) */ + + if (q - data > SECTION_LENGTH - 4) { + err = 1; + break; + } if(st->codec->extradata_size == 4) { memcpy(q, st->codec->extradata, 4); q += 4; @@ -407,6 +419,14 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) desc_length_ptr[0] = val >> 8; desc_length_ptr[1] = val; } + + if (err) + av_log(s, AV_LOG_ERROR, + "The PMT section is too small for stream %d and following.\n" + "Try reducing the number of languages in the audio streams " + "or the total number of streams.\n", + i); + mpegts_write_section1(&service->pmt, PMT_TID, service->sid, 0, 0, 0, data, q - data); return 0; |