diff options
author | Sebastian Dröge <sebastian@centricular.com> | 2019-12-03 15:45:26 +0200 |
---|---|---|
committer | Tim-Philipp Müller <tim@centricular.com> | 2019-12-06 11:27:12 +0000 |
commit | 39a67657d7153662ed08eab6cb8da6d4e621f055 (patch) | |
tree | c3c65293475e311fd3c952b9360f59bb6a060673 | |
parent | 9fb5c5f466fb707931bf783d9518c661c53f334e (diff) | |
download | gstreamer-plugins-bad-39a67657d7153662ed08eab6cb8da6d4e621f055.tar.gz |
interlace: Store unsigned integers in unsigned integer types
And add some assertions to guard against overflows and out of bounds
reads.
-rw-r--r-- | gst/interlace/gstinterlace.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/gst/interlace/gstinterlace.c b/gst/interlace/gstinterlace.c index 8121eec01..39bcab99d 100644 --- a/gst/interlace/gstinterlace.c +++ b/gst/interlace/gstinterlace.c @@ -98,11 +98,11 @@ struct _GstInterlace int src_fps_d; GstBuffer *stored_frame; - gint stored_fields; - gint phase_index; - int field_index; /* index of the next field to push, 0=top 1=bottom */ + guint stored_fields; + guint phase_index; + guint field_index; /* index of the next field to push, 0=top 1=bottom */ GstClockTime timebase; - int fields_since_timebase; + guint fields_since_timebase; guint pattern_offset; /* initial offset into the pattern */ gboolean passthrough; }; @@ -849,7 +849,7 @@ gst_interlace_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer) GstInterlace *interlace = GST_INTERLACE (parent); GstFlowReturn ret = GST_FLOW_OK; gint num_fields = 0; - int current_fields; + guint current_fields; const PulldownFormat *format; GstClockTime timestamp; @@ -902,6 +902,7 @@ gst_interlace_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer) current_fields = format->n_fields[interlace->phase_index]; /* increment the phase index */ interlace->phase_index++; + g_assert (interlace->phase_index < G_N_ELEMENTS (format->n_fields)); if (!format->n_fields[interlace->phase_index]) { interlace->phase_index = 0; } @@ -911,7 +912,7 @@ gst_interlace_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer) num_fields = interlace->stored_fields + current_fields; while (num_fields >= 2) { GstBuffer *output_buffer; - int n_output_fields; + guint n_output_fields; gboolean interlaced = FALSE; GST_DEBUG ("have %d fields, %d current, %d stored", @@ -948,6 +949,9 @@ gst_interlace_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer) gst_interlace_decorate_buffer (interlace, output_buffer, n_output_fields, interlaced); + /* Guard against overflows here. If this ever happens, resetting the phase + * above would never happen because of some bugs */ + g_assert (interlace->fields_since_timebase <= G_MAXUINT - n_output_fields); interlace->fields_since_timebase += n_output_fields; interlace->field_index ^= (n_output_fields & 1); |