From eec64e372b944c66bb4d5138e223fb1721f39c29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Thu, 11 Apr 2024 01:49:40 +0100 Subject: [PATCH] rtph264depay: fix FU-B handling Skip extra 16-bit DON in FU-B header. Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/issues/806 Part-of: --- .../gst/rtp/gstrtph264depay.c | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/subprojects/gst-plugins-good/gst/rtp/gstrtph264depay.c b/subprojects/gst-plugins-good/gst/rtp/gstrtph264depay.c index 10b12cee6f..8a94fc08cb 100644 --- a/subprojects/gst-plugins-good/gst/rtp/gstrtph264depay.c +++ b/subprojects/gst-plugins-good/gst/rtp/gstrtph264depay.c @@ -1307,6 +1307,11 @@ gst_rtp_h264_depay_process (GstRTPBaseDepayload * depayload, GstRTPBuffer * rtp) /* FU-B Fragmentation unit 5.8 */ gboolean S, E; + guint fu_hdr_size = (nal_unit_type == 28) ? 2 : 4; + + if (payload_len < fu_hdr_size) + goto short_payload; + /* +---------------+ * |0|1|2|3|4|5|6|7| * +-+-+-+-+-+-+-+-+ @@ -1344,9 +1349,9 @@ gst_rtp_h264_depay_process (GstRTPBaseDepayload * depayload, GstRTPBuffer * rtp) /* reconstruct NAL header */ nal_header = (payload[0] & 0xe0) | (payload[1] & 0x1f); - /* Strip type header, FU header */ - payload += 2; - payload_len -= 2; + /* Strip type header, FU header, and FU-B DON (if present) */ + payload += fu_hdr_size; + payload_len -= fu_hdr_size; nalu_size = 1 + payload_len; outsize = nalu_size + sizeof (sync_bytes); @@ -1387,9 +1392,9 @@ gst_rtp_h264_depay_process (GstRTPBaseDepayload * depayload, GstRTPBuffer * rtp) } rtph264depay->last_fu_seqnum = gst_rtp_buffer_get_seq (rtp); - /* strip off FU indicator and FU header bytes */ - payload += 2; - payload_len -= 2; + /* strip off FU indicator, FU header bytes and FU-B DON (if present) */ + payload += fu_hdr_size; + payload_len -= fu_hdr_size; outsize = payload_len; outbuf = gst_buffer_new_and_alloc (outsize); @@ -1449,6 +1454,12 @@ empty_packet: gst_rtp_base_depayload_dropped (depayload); return NULL; } +short_payload: + { + GST_DEBUG_OBJECT (rtph264depay, "short payload"); + gst_rtp_base_depayload_dropped (depayload); + return NULL; + } undefined_type: { GST_ELEMENT_WARNING (rtph264depay, STREAM, DECODE,