Commit 842b6c14 authored by Michael Niedermayer's avatar Michael Niedermayer

avformat/mpegtsenc: Check data array size in mpegts_write_pmt()

Prevents out of array writes
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent af786236
...@@ -259,7 +259,7 @@ static void mpegts_write_pat(AVFormatContext *s) ...@@ -259,7 +259,7 @@ static void mpegts_write_pat(AVFormatContext *s)
data, q - data); data, q - data);
} }
static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
{ {
MpegTSWrite *ts = s->priv_data; MpegTSWrite *ts = s->priv_data;
uint8_t data[1012], *q, *desc_length_ptr, *program_info_length_ptr; uint8_t data[1012], *q, *desc_length_ptr, *program_info_length_ptr;
...@@ -315,6 +315,10 @@ static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) ...@@ -315,6 +315,10 @@ static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
stream_type = STREAM_TYPE_PRIVATE_DATA; stream_type = STREAM_TYPE_PRIVATE_DATA;
break; break;
} }
if (q - data > sizeof(data) - 32)
return AVERROR(EINVAL);
*q++ = stream_type; *q++ = stream_type;
put16(&q, 0xe000 | ts_st->pid); put16(&q, 0xe000 | ts_st->pid);
desc_length_ptr = q; desc_length_ptr = q;
...@@ -346,7 +350,7 @@ static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) ...@@ -346,7 +350,7 @@ static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
len_ptr = q++; len_ptr = q++;
*len_ptr = 0; *len_ptr = 0;
for (p = lang->value; next && *len_ptr < 255 / 4 * 4; p = next + 1) { for (p = lang->value; next && *len_ptr < 255 / 4 * 4 && q - data < sizeof(data) - 4; p = next + 1) {
next = strchr(p, ','); next = strchr(p, ',');
if (strlen(p) != 3 && (!next || next != p + 3)) if (strlen(p) != 3 && (!next || next != p + 3))
continue; /* not a 3-letter code */ continue; /* not a 3-letter code */
...@@ -422,7 +426,7 @@ static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) ...@@ -422,7 +426,7 @@ static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
*q++ = 0x56; *q++ = 0x56;
len_ptr = q++; len_ptr = q++;
while (strlen(language) >= 3) { while (strlen(language) >= 3 && q - data < sizeof(data) - 6) {
*q++ = *language++; *q++ = *language++;
*q++ = *language++; *q++ = *language++;
*q++ = *language++; *q++ = *language++;
...@@ -476,6 +480,7 @@ static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) ...@@ -476,6 +480,7 @@ static void mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
} }
mpegts_write_section1(&service->pmt, PMT_TID, service->sid, ts->tables_version, 0, 0, mpegts_write_section1(&service->pmt, PMT_TID, service->sid, ts->tables_version, 0, 0,
data, q - data); data, q - data);
return 0;
} }
/* NOTE: str == NULL is accepted for an empty string */ /* NOTE: str == NULL is accepted for an empty string */
......
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