From a1380b251cee714d04d719f724fa1a5b5b54eb1c Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Tue, 3 May 2016 18:38:23 +0200 Subject: [PATCH] Fix an out-of-bounds write (found by asan). --- x264_speed_control.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/x264_speed_control.cpp b/x264_speed_control.cpp index 3ed3ece..aae7a18 100644 --- a/x264_speed_control.cpp +++ b/x264_speed_control.cpp @@ -176,14 +176,16 @@ void X264SpeedControl::before_frame(float new_buffer_fill, int new_buffer_size, timestamp = t; // update the time predictor - int cpu_time = cpu_time_last_frame; - cplx_num *= cplx_decay; - cplx_den *= cplx_decay; - cplx_num += cpu_time / presets[preset].time; - ++cplx_den; - - stat.avg_preset += preset; - ++stat.den; + if (preset >= 0) { + int cpu_time = cpu_time_last_frame; + cplx_num *= cplx_decay; + cplx_den *= cplx_decay; + cplx_num += cpu_time / presets[preset].time; + ++cplx_den; + + stat.avg_preset += preset; + ++stat.den; + } stat.min_buffer = min(buffer_fill, stat.min_buffer); stat.max_buffer = max(buffer_fill, stat.max_buffer); -- 2.39.2