1 From 12770701856a05b6b3cd706f708f8e9a4e8a1336 Mon Sep 17 00:00:00 2001
2 From: Michael Niedermayer <michaelni@gmx.at>
3 Date: Thu, 13 Feb 2014 13:59:51 +0100
4 Subject: [PATCH] avformat/mpegtsenc: Check data array size in
7 Upstream-Status: Backport
9 COmmit 12770701856a05b6b3cd706f708f8e9a4e8a1336 release/0.11
11 Prevents out of array writes
13 Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
14 (cherry picked from commit 842b6c14bcfc1c5da1a2d288fd65386eb8c158ad)
18 libavformat/mpegtsenc.c
19 (cherry picked from commit e87de3f50b765134588d0b048c32ed4b8acc16fb)
21 Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
23 libavformat/mpegtsenc.c | 9 +++++++--
24 1 files changed, 7 insertions(+), 2 deletions(-)
26 diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
27 index 793e205..a12d19f 100644
28 --- a/gst-libs/ext/libav/libavformat/mpegtsenc.c
29 +++ b/gst-libs/ext/libav/libavformat/mpegtsenc.c
30 @@ -240,7 +240,7 @@ static void mpegts_write_pat(AVFormatContext *s)
34 -static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
35 +static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
37 // MpegTSWrite *ts = s->priv_data;
38 uint8_t data[1012], *q, *desc_length_ptr, *program_info_length_ptr;
39 @@ -293,6 +293,10 @@ static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
40 stream_type = STREAM_TYPE_PRIVATE_DATA;
44 + if (q - data > sizeof(data) - 32)
45 + return AVERROR(EINVAL);
48 put16(&q, 0xe000 | ts_st->pid);
50 @@ -324,7 +328,7 @@ static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
54 - for (p = lang->value; next && *len_ptr < 255 / 4 * 4; p = next + 1) {
55 + for (p = lang->value; next && *len_ptr < 255 / 4 * 4 && q - data < sizeof(data) - 4; p = next + 1) {
56 next = strchr(p, ',');
57 if (strlen(p) != 3 && (!next || next != p + 3))
58 continue; /* not a 3-letter code */
59 @@ -386,6 +390,7 @@ static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
61 mpegts_write_section1(&service->pmt, PMT_TID, service->sid, 0, 0, 0,
66 /* NOTE: str == NULL is accepted for an empty string */