summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGwenole Beauchesne <gwenole.beauchesne@intel.com>2012-10-01 09:48:06 +0200
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>2014-03-24 19:38:13 +0100
commit8dc7ab49fe430a6626da7552dd41db8603a67811 (patch)
treeaf7e19c163951bffc636bc947e4950f53086fa29
parente61ae7ffa2560d4954dee63a64993369ca16c705 (diff)
downloadgstreamer-plugins-bad-8dc7ab49fe430a6626da7552dd41db8603a67811.tar.gz
codecparsers: h264: add gst_h264_parse_nalu_header() helper.
Add helper to parse the NALU header. Move bounds checking to there. https://bugzilla.gnome.org/show_bug.cgi?id=685215 Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
-rw-r--r--gst-libs/gst/codecparsers/gsth264parser.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/gst-libs/gst/codecparsers/gsth264parser.c b/gst-libs/gst/codecparsers/gsth264parser.c
index a89db0d3a..bc0101447 100644
--- a/gst-libs/gst/codecparsers/gsth264parser.c
+++ b/gst-libs/gst/codecparsers/gsth264parser.c
@@ -200,16 +200,20 @@ gst_h264_parser_get_pps (GstH264NalParser * nalparser, guint8 pps_id)
return NULL;
}
-static inline void
-set_nalu_datas (GstH264NalUnit * nalu)
+static gboolean
+gst_h264_parse_nalu_header (GstH264NalUnit * nalu)
{
guint8 *data = nalu->data + nalu->offset;
+ if (nalu->size < 1)
+ return FALSE;
+
nalu->type = (data[0] & 0x1f);
nalu->ref_idc = (data[0] & 0x60) >> 5;
nalu->idr_pic_flag = (nalu->type == 5 ? 1 : 0);
GST_DEBUG ("Nal type %u, ref_idc %u", nalu->type, nalu->ref_idc);
+ return TRUE;
}
/****** Parsing functions *****/
@@ -996,14 +1000,20 @@ gst_h264_parser_identify_nalu_unchecked (GstH264NalParser * nalparser,
return GST_H264_PARSER_ERROR;
}
- nalu->valid = TRUE;
nalu->sc_offset = offset + off1;
nalu->offset = offset + off1 + 3;
nalu->data = (guint8 *) data;
+ nalu->size = size - nalu->offset;
+
+ if (!gst_h264_parse_nalu_header (nalu)) {
+ GST_WARNING ("error parsing \"NAL unit header\"");
+ nalu->size = 0;
+ return GST_H264_PARSER_BROKEN_DATA;
+ }
- set_nalu_datas (nalu);
+ nalu->valid = TRUE;
/* sc might have 2 or 3 0-bytes */
if (nalu->sc_offset > 0 && data[nalu->sc_offset - 1] == 00
@@ -1018,8 +1028,6 @@ gst_h264_parser_identify_nalu_unchecked (GstH264NalParser * nalparser,
return GST_H264_PARSER_OK;
}
- nalu->size = size - nalu->offset;
-
return GST_H264_PARSER_OK;
}
@@ -1115,10 +1123,11 @@ gst_h264_parser_identify_nalu_avc (GstH264NalParser * nalparser,
nalu->data = (guint8 *) data;
- set_nalu_datas (nalu);
-
- if (nalu->size < 2)
+ if (!gst_h264_parse_nalu_header (nalu)) {
+ GST_WARNING ("error parsing \"NAL unit header\"");
+ nalu->size = 0;
return GST_H264_PARSER_BROKEN_DATA;
+ }
nalu->valid = TRUE;