From 9029631f752d004912a02b775002579f414a2b33 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Wed, 6 May 2020 22:18:12 -0400 Subject: [PATCH] h265parser: Fix NAL size check for identification 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: --- gst-libs/gst/codecparsers/gsth265parser.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gst-libs/gst/codecparsers/gsth265parser.c b/gst-libs/gst/codecparsers/gsth265parser.c index 7dea82227a..dc8db4c2ec 100644 --- a/gst-libs/gst/codecparsers/gsth265parser.c +++ b/gst-libs/gst/codecparsers/gsth265parser.c @@ -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--;