h265parser: Fix NAL size check for identification
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Thu, 7 May 2020 02:18:12 +0000 (22:18 -0400)
committerNicolas Dufresne <nicolas.dufresne@collabora.com>
Thu, 7 May 2020 16:08:36 +0000 (12:08 -0400)
Unlike H264, H265 requires 2 bytes after the start code to allow NAL
identification. This would otherwise report a broken NAL and skip
important data.

Fixes #1287

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1251>

gst-libs/gst/codecparsers/gsth265parser.c

index 7dea822..dc8db4c 100644 (file)
@@ -1414,6 +1414,13 @@ gst_h265_parser_identify_nalu_unchecked (GstH265Parser * parser,
 
   nalu->sc_offset = offset + off1;
 
+  /* The scanner ensures one byte passed the start code but to
+   * identify an HEVC NAL, we need 2. */
+  if (size - nalu->sc_offset - 3 < 2) {
+    GST_DEBUG ("Not enough bytes after start code to identify");
+    return GST_H265_PARSER_NO_NAL;
+  }
+
   /* sc might have 2 or 3 0-bytes */
   if (nalu->sc_offset > 0 && data[nalu->sc_offset - 1] == 00)
     nalu->sc_offset--;