Package: gst-plugins-bad1.0 / 1.4.4-2.1+deb8u2

0004-mpegtssection-Add-more-section-size-checks.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
From d58f668ece8795bddb3316832e1848c7b7cf38ac Mon Sep 17 00:00:00 2001
From: Edward Hervey <edward@centricular.com>
Date: Sat, 26 Nov 2016 10:44:43 +0100
Subject: [PATCH] mpegtssection: Add more section size checks

The smallest section ever needs to be at least 3 bytes (i.e. just the short
header).
Non-short headers need to be at least 11 bytes long (3 for the minimum header,
5 for the non-short header, and 4 for the CRC).

https://bugzilla.gnome.org/show_bug.cgi?id=775048
---
 gst-libs/gst/mpegts/gstmpegtssection.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

Index: gst-plugins-bad1.0-1.4.4/gst-libs/gst/mpegts/gstmpegtssection.c
===================================================================
--- gst-plugins-bad1.0-1.4.4.orig/gst-libs/gst/mpegts/gstmpegtssection.c
+++ gst-plugins-bad1.0-1.4.4/gst-libs/gst/mpegts/gstmpegtssection.c
@@ -1175,13 +1175,20 @@ gst_mpegts_section_new (guint16 pid, gui
   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;
 
@@ -1196,6 +1203,13 @@ gst_mpegts_section_new (guint16 pid, gui
   /* 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 */
@@ -1225,6 +1239,13 @@ short_packet:
     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;
+  }
 }
 
 /**