diff options
author | Gwenole Beauchesne <gwenole.beauchesne@intel.com> | 2012-10-01 09:48:06 +0200 |
---|---|---|
committer | Gwenole Beauchesne <gwenole.beauchesne@intel.com> | 2012-10-10 10:43:07 +0200 |
commit | 6271fa39205a5171771fdf19a638ac9a720fd6a0 (patch) | |
tree | d5e0fb366456cd357d3a18211b1225ea46fa2cf1 | |
parent | 88c1389c3ba4764e9c9587fe69e53e9fcdb104ff (diff) |
codecparsers: h264: add gst_h264_parse_nalu_header() helper.
Add helper to parse the NALU header. Move bounds checking to there.
Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
-rw-r--r-- | gst-libs/gst/codecparsers/gsth264parser.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/gst-libs/gst/codecparsers/gsth264parser.c b/gst-libs/gst/codecparsers/gsth264parser.c index a41891a4f..f10e3bdd9 100644 --- a/gst-libs/gst/codecparsers/gsth264parser.c +++ b/gst-libs/gst/codecparsers/gsth264parser.c @@ -474,16 +474,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; } static inline gint @@ -1234,7 +1238,6 @@ gst_h264_parser_identify_nalu_unchecked (GstH264NalParser * nalparser, return GST_H264_PARSER_ERROR; } - nalu->valid = TRUE; nalu->sc_offset = offset + off1; /* sc might have 2 or 3 0-bytes */ @@ -1243,8 +1246,15 @@ gst_h264_parser_identify_nalu_unchecked (GstH264NalParser * nalparser, nalu->offset = offset + off1 + 3; nalu->data = (guint8 *) data; + nalu->size = size - nalu->offset; - set_nalu_datas (nalu); + 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; if (nalu->type == GST_H264_NAL_SEQ_END || nalu->type == GST_H264_NAL_STREAM_END) { @@ -1253,8 +1263,6 @@ gst_h264_parser_identify_nalu_unchecked (GstH264NalParser * nalparser, return GST_H264_PARSER_OK; } - nalu->size = size - nalu->offset; - return GST_H264_PARSER_OK; } @@ -1347,10 +1355,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; |