avtp: CVF - Do not infinite loop trying to fragment zero sized NAL unit
authorEderson de Souza <ederson.desouza@intel.com>
Mon, 8 Jul 2019 21:19:07 +0000 (14:19 -0700)
committerEderson de Souza <ederson.desouza@intel.com>
Tue, 30 Jul 2019 18:34:31 +0000 (11:34 -0700)
Zero sized NAL-units should not happen, but if they do, do not infinite
loop. Added also a unit test for this case.

ext/avtp/gstavtpcvfpay.c
tests/check/elements/avtpcvfpay.c

index 2567632..c2eaaa0 100644 (file)
@@ -249,6 +249,11 @@ gst_avtp_cvf_pay_extract_nals (GstAvtpCvfPay * avtpcvfpay,
       nal_len = (nal_len << 8) + data[i];
     }
 
+    if (nal_len == 0) {
+      GST_WARNING_OBJECT (avtpcvfpay, "Invalid NAL unit size: 0");
+      break;
+    }
+
     offset += avtpcvfpay->nal_length_size;
     data += avtpcvfpay->nal_length_size;
     size -= avtpcvfpay->nal_length_size;
index 9f92ba8..9e6c13b 100644 (file)
@@ -137,6 +137,38 @@ compare_h264_avtpdu (struct avtp_stream_pdu *pdu, GstBuffer * buffer)
   return result;
 }
 
+GST_START_TEST (test_payloader_zero_sized_nal)
+{
+  GstHarness *h;
+  GstBuffer *in;
+  GstMapInfo map;
+
+  /* Create the harness for the avtpcvfpay */
+  h = gst_harness_new_parse
+      ("avtpcvfpay streamid=0xAABBCCDDEEFF0001 mtt=1000000 tu=1000000 processing-deadline=0");
+  gst_harness_set_src_caps (h, generate_caps (4));
+
+  /* We have the buffer with the nal size (4 bytes) and the nal (4 bytes), but
+   * nal size will be zero */
+  in = gst_harness_create_buffer (h, 8);
+  GST_BUFFER_DTS (in) = 1000000;
+  GST_BUFFER_PTS (in) = 2000000;
+
+  gst_buffer_map (in, &map, GST_MAP_READWRITE);
+  map.data[0] = map.data[1] = map.data[2] = map.data[3] = 0;    /* Set NAL size to 0 */
+  map.data[4] = 1;              /* Some dummy vcl NAL type */
+  gst_buffer_unmap (in, &map);
+
+  gst_harness_push (h, in);
+
+  /* No buffer shuld come out */
+  fail_unless_equals_int (gst_harness_buffers_received (h), 0);
+
+  gst_harness_teardown (h);
+}
+
+GST_END_TEST;
+
 GST_START_TEST (test_payloader_no_codec_data)
 {
   GstHarness *h;
@@ -641,6 +673,7 @@ avtpcvfpay_suite (void)
   tcase_add_test (tc_chain, test_payloader_invalid_caps);
   tcase_add_test (tc_chain, test_payloader_properties);
   tcase_add_test (tc_chain, test_payloader_no_codec_data);
+  tcase_add_test (tc_chain, test_payloader_zero_sized_nal);
 
   return s;
 }