mpegtspacketizer: Make sure in all cases that we have enough data left for reading a section start

In some cases we ended up parsing sections without.
This commit is contained in:
Sebastian Dröge 2016-11-22 12:42:45 +02:00
parent d130a19c89
commit ab4bb225bd

View file

@ -1051,9 +1051,10 @@ accumulate_data:
res = section; res = section;
} }
/* FIXME : We need at least 8 bytes with current algorithm :( section_start:
/* FIXME : We need at least 3 bytes (or 8 for long packets) with current algorithm :(
* We might end up losing sections that start across two packets (srsl...) */ * We might end up losing sections that start across two packets (srsl...) */
if (data > packet->data_end - 8 || *data == 0xff) { if (data > packet->data_end - 3 || *data == 0xff) {
/* flush stuffing bytes and leave */ /* flush stuffing bytes and leave */
mpegts_packetizer_clear_section (stream); mpegts_packetizer_clear_section (stream);
goto out; goto out;
@ -1062,8 +1063,6 @@ accumulate_data:
/* We have more data to process ... */ /* We have more data to process ... */
GST_DEBUG ("PID 0x%04x, More section present in packet (remaining bytes:%" GST_DEBUG ("PID 0x%04x, More section present in packet (remaining bytes:%"
G_GSIZE_FORMAT ")", stream->pid, (gsize) (packet->data_end - data)); G_GSIZE_FORMAT ")", stream->pid, (gsize) (packet->data_end - data));
section_start:
GST_MEMDUMP ("section_start", data, packet->data_end - data); GST_MEMDUMP ("section_start", data, packet->data_end - data);
data_start = data; data_start = data;
/* Beginning of a new section */ /* Beginning of a new section */
@ -1116,6 +1115,10 @@ section_start:
data += 2; data += 2;
if (long_packet) { if (long_packet) {
/* Do we have enough data for a long packet? */
if (data > packet->data_end - 5)
goto out;
/* subtable_extension (always present, we are in a long section) */ /* subtable_extension (always present, we are in a long section) */
/* subtable extension : 16 bit */ /* subtable extension : 16 bit */
subtable_extension = GST_READ_UINT16_BE (data); subtable_extension = GST_READ_UINT16_BE (data);