_parse_pat (GstMpegtsSection * section)
{
GPtrArray *pat;
- guint16 i = 0, nb_programs;
+ guint16 i, nb_programs;
GstMpegtsPatProgram *program;
guint8 *data, *end;
g_ptr_array_new_full (nb_programs,
(GDestroyNotify) _mpegts_pat_program_free);
- while (data < end - 4) {
+ GST_LOG ("nb_programs %u", nb_programs);
+
+ for (i = 0; i < nb_programs; i++) {
program = g_slice_new0 (GstMpegtsPatProgram);
program->program_number = GST_READ_UINT16_BE (data);
data += 2;
data += 2;
g_ptr_array_index (pat, i) = program;
-
- i++;
}
pat->len = nb_programs;
GstMpegtsSection *res = NULL;
guint8 tmp;
guint8 table_id;
- guint16 section_length;
+ guint16 section_length = 0;
+
+ /* The smallest section ever is 3 bytes */
+ if (G_UNLIKELY (data_size < 3))
+ goto short_packet;
/* Check for length */
section_length = GST_READ_UINT16_BE (data + 1) & 0x0FFF;
if (G_UNLIKELY (data_size < section_length + 3))
goto short_packet;
+ GST_LOG ("data_size:%" G_GSIZE_FORMAT " section_length:%u",
+ data_size, section_length);
+
/* Table id is in first byte */
table_id = *data;
/* section_length (already parsed) : 12 bit */
res->section_length = section_length + 3;
if (!res->short_section) {
+ /* A long packet needs to be at least 11 bytes long
+ * _ 3 for the bytes above
+ * _ 5 for the bytes below
+ * _ 4 for the CRC */
+ if (G_UNLIKELY (data_size < 11))
+ goto bad_long_packet;
+
/* CRC is after section_length (-4 for the size of the CRC) */
res->crc = GST_READ_UINT32_BE (res->data + res->section_length - 4);
/* Skip to after section_length */
g_free (data);
return NULL;
}
+bad_long_packet:
+ {
+ GST_WARNING ("PID 0x%04x long section is too short (%" G_GSIZE_FORMAT
+ " bytes, need at least 11)", pid, data_size);
+ gst_mpegts_section_unref (res);
+ return NULL;
+ }
}
/**
(value = gst_structure_get_value (str, "codec_data"))) {
GstMapInfo map;
guint8 *data;
+ guint num_nal_arrays;
GST_DEBUG_OBJECT (h265parse, "have packetized h265");
/* make note for optional split processing */
GST_DEBUG_OBJECT (h265parse, "nal length size %u",
h265parse->nal_length_size);
+ num_nal_arrays = data[22];
off = 23;
- for (i = 0; i < data[22]; i++) {
+
+ for (i = 0; i < num_nal_arrays; i++) {
+ if (off + 3 >= size) {
+ gst_buffer_unmap (codec_data, &map);
+ goto hvcc_too_small;
+ }
+
num_nals = GST_READ_UINT16_BE (data + off + 1);
for (j = 0; j < num_nals; j++) {
parseres = gst_h265_parser_identify_nalu_hevc (h265parse->nalparser,