Skip to content

Commit

Permalink
vp9 svc: fix interger overflow
Browse files Browse the repository at this point in the history
Overflow was happening in two places:
one in set_encoder_config(), where the input
layer_target_bitrates are converted from kbps to bps,
the other in vp9_calc_pframe_target_size_one_pass_vbr(),
where target is scaled by kf_ratio.

vp9_ratectrl.c:2039: runtime error: signed integer overflow:
-137438983 * 25 cannot be represented in type 'int'

Bug: chromium:1475943

Change-Id: I1ab0980862548c8827fae461df9a7a74425209ff
  • Loading branch information
marco99zz committed Aug 29, 2023
1 parent e052ada commit 6da1bd0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion vp9/encoder/vp9_ratectrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2036,7 +2036,11 @@ int vp9_calc_pframe_target_size_one_pass_vbr(const VP9_COMP *cpi) {
int vp9_calc_iframe_target_size_one_pass_vbr(const VP9_COMP *cpi) {
static const int kf_ratio = 25;
const RATE_CONTROL *rc = &cpi->rc;
const int target = rc->avg_frame_bandwidth * kf_ratio;
int target = rc->avg_frame_bandwidth;
if (target > INT_MAX / kf_ratio)
target = INT_MAX;
else
target = rc->avg_frame_bandwidth * kf_ratio;
return vp9_rc_clamp_iframe_target_size(cpi, target);
}

Expand Down
8 changes: 6 additions & 2 deletions vp9/vp9_cx_iface.c
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,12 @@ static vpx_codec_err_t set_encoder_config(

for (sl = 0; sl < oxcf->ss_number_layers; ++sl) {
for (tl = 0; tl < oxcf->ts_number_layers; ++tl) {
oxcf->layer_target_bitrate[sl * oxcf->ts_number_layers + tl] =
1000 * cfg->layer_target_bitrate[sl * oxcf->ts_number_layers + tl];
const int layer = sl * oxcf->ts_number_layers + tl;
if (cfg->layer_target_bitrate[layer] > INT_MAX / 1000)
oxcf->layer_target_bitrate[layer] = INT_MAX;
else
oxcf->layer_target_bitrate[layer] =
1000 * cfg->layer_target_bitrate[layer];
}
}
if (oxcf->ss_number_layers == 1 && oxcf->pass != 0) {
Expand Down

0 comments on commit 6da1bd0

Please sign in to comment.