shithub: libvpx

Download patch

ref: 826d7ca4d970caaa90d68f5096f06ee72bbdd688
parent: 002f14078ff6aa1f0c1548aa1902b3af9d42087e
parent: 5f345a9246b71374cbedeb28b0e0b0101701732a
author: Yaowu Xu <yaowu@google.com>
date: Thu Jul 8 15:59:34 EDT 2021

Merge "Avoid overflow in calc_iframe_target_size" into main

--- a/vp8/encoder/ratectrl.c
+++ b/vp8/encoder/ratectrl.c
@@ -349,8 +349,12 @@
   }
 
   if (cpi->oxcf.rc_max_intra_bitrate_pct) {
-    unsigned int max_rate =
-        cpi->per_frame_bandwidth * cpi->oxcf.rc_max_intra_bitrate_pct / 100;
+    unsigned int max_rate;
+    // This product may overflow unsigned int
+    uint64_t product = cpi->per_frame_bandwidth;
+    product *= cpi->oxcf.rc_max_intra_bitrate_pct;
+    product /= 100;
+    max_rate = (unsigned int)VPXMIN(INT_MAX, product);
 
     if (target > max_rate) target = max_rate;
   }