h264parse, h265parse: Fix potential integer overflow

Fixes: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/2961
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5295>
This commit is contained in:
Seungha Yang 2023-09-07 20:06:02 +09:00 committed by GStreamer Marge Bot
parent 962384846d
commit efe35a3f6c
2 changed files with 50 additions and 32 deletions

View file

@ -3384,7 +3384,8 @@ gst_h264_parse_pre_push_frame (GstBaseParse * parse, GstBaseParseFrame * frame)
GstH264ClockTimestamp *tim = GstH264ClockTimestamp *tim =
&h264parse->pic_timing_sei.clock_timestamp[i]; &h264parse->pic_timing_sei.clock_timestamp[i];
gint field_count = -1; gint field_count = -1;
guint n_frames; guint64 n_frames_tmp;
guint n_frames = G_MAXUINT32;
GstVideoTimeCodeFlags flags = 0; GstVideoTimeCodeFlags flags = 0;
guint64 scale_n, scale_d; guint64 scale_n, scale_d;
@ -3459,24 +3460,32 @@ gst_h264_parse_pre_push_frame (GstBaseParse * parse, GstBaseParseFrame * frame)
* using time_scale / num_units_in_tick * using time_scale / num_units_in_tick
* => "n_frames = nFrames * (1 + nuit_field_based_flag) / 2". * => "n_frames = nFrames * (1 + nuit_field_based_flag) / 2".
*/ */
scale_n = h264parse->parsed_fps_n * vui->num_units_in_tick scale_n = (guint64) h264parse->parsed_fps_n * vui->num_units_in_tick;
* (1 + tim->nuit_field_based_flag); scale_d = (guint64) h264parse->parsed_fps_d * vui->time_scale;
scale_d = h264parse->parsed_fps_d * vui->time_scale;
n_frames = gst_util_uint64_scale (tim->n_frames, scale_n, scale_d); n_frames_tmp = gst_util_uint64_scale (tim->n_frames, scale_n, scale_d);
if (n_frames_tmp <= G_MAXUINT32) {
if (tim->nuit_field_based_flag)
n_frames_tmp *= 2;
GST_LOG_OBJECT (h264parse, if (n_frames_tmp <= G_MAXUINT32)
"Add time code meta %02u:%02u:%02u:%02u", n_frames = (guint) n_frames_tmp;
tim->hours_value, tim->minutes_value, tim->seconds_value, n_frames); }
gst_buffer_add_video_time_code_meta_full (parse_buffer, if (n_frames != G_MAXUINT32) {
h264parse->parsed_fps_n, GST_LOG_OBJECT (h264parse,
h264parse->parsed_fps_d, "Add time code meta %02u:%02u:%02u:%02u",
NULL, tim->hours_value, tim->minutes_value, tim->seconds_value, n_frames);
flags,
tim->hours_flag ? tim->hours_value : 0, gst_buffer_add_video_time_code_meta_full (parse_buffer,
tim->minutes_flag ? tim->minutes_value : 0, h264parse->parsed_fps_n,
tim->seconds_flag ? tim->seconds_value : 0, n_frames, field_count); h264parse->parsed_fps_d,
NULL,
flags,
tim->hours_flag ? tim->hours_value : 0,
tim->minutes_flag ? tim->minutes_value : 0,
tim->seconds_flag ? tim->seconds_value : 0, n_frames, field_count);
}
} }
h264parse->num_clock_timestamp = 0; h264parse->num_clock_timestamp = 0;

View file

@ -3055,7 +3055,8 @@ gst_h265_parse_pre_push_frame (GstBaseParse * parse, GstBaseParseFrame * frame)
for (i = 0; i < h265parse->time_code.num_clock_ts; i++) { for (i = 0; i < h265parse->time_code.num_clock_ts; i++) {
gint field_count = -1; gint field_count = -1;
guint n_frames; guint64 n_frames_tmp;
guint n_frames = G_MAXUINT32;
GstVideoTimeCodeFlags flags = 0; GstVideoTimeCodeFlags flags = 0;
guint64 scale_n, scale_d; guint64 scale_n, scale_d;
@ -3128,25 +3129,33 @@ gst_h265_parse_pre_push_frame (GstBaseParse * parse, GstBaseParseFrame * frame)
* = nFrames * ------------------------------------------------------------------ * = nFrames * ------------------------------------------------------------------
* fps_d * vui_time_scale * fps_d * vui_time_scale
*/ */
scale_n = h265parse->parsed_fps_n * vui->num_units_in_tick scale_n = (guint64) h265parse->parsed_fps_n * vui->num_units_in_tick;
* (1 + h265parse->time_code.units_field_based_flag[i]); scale_d = (guint64) h265parse->parsed_fps_d * vui->time_scale;
scale_d = h265parse->parsed_fps_d * vui->time_scale;
n_frames = n_frames_tmp =
gst_util_uint64_scale_int (h265parse->time_code.n_frames[i], scale_n, gst_util_uint64_scale_int (h265parse->time_code.n_frames[i], scale_n,
scale_d); scale_d);
if (n_frames_tmp <= G_MAXUINT32) {
if (h265parse->time_code.units_field_based_flag[i])
n_frames_tmp *= 2;
gst_buffer_add_video_time_code_meta_full (parse_buffer, if (n_frames_tmp <= G_MAXUINT32)
h265parse->parsed_fps_n, n_frames = (guint) n_frames_tmp;
h265parse->parsed_fps_d, }
NULL,
flags, if (n_frames != G_MAXUINT32) {
h265parse->time_code.hours_flag[i] ? h265parse->time_code. gst_buffer_add_video_time_code_meta_full (parse_buffer,
hours_value[i] : 0, h265parse->parsed_fps_n,
h265parse->time_code.minutes_flag[i] ? h265parse->time_code. h265parse->parsed_fps_d,
minutes_value[i] : 0, NULL,
h265parse->time_code.seconds_flag[i] ? h265parse->time_code. flags,
seconds_value[i] : 0, n_frames, field_count); h265parse->time_code.hours_flag[i] ? h265parse->time_code.
hours_value[i] : 0,
h265parse->time_code.minutes_flag[i] ? h265parse->time_code.
minutes_value[i] : 0,
h265parse->time_code.seconds_flag[i] ? h265parse->time_code.
seconds_value[i] : 0, n_frames, field_count);
}
} }
} }