diff options
author | Jerome Jiang <jianj@google.com> | 2018-03-20 15:29:23 -0700 |
---|---|---|
committer | Jerome Jiang <jianj@google.com> | 2018-03-20 15:31:20 -0700 |
commit | da4d796a5eb83754256b021cb7e4cf44583048d4 (patch) | |
tree | 40a617e09ecf6eec40f7f7b600434c8c11b621fe /libvpx | |
parent | 93c7708bb96ba584a2a4bc20ec2f50d490e5ad1c (diff) | |
download | libvpx-da4d796a5eb83754256b021cb7e4cf44583048d4.tar.gz |
libvpx: cherry pick fix to OOB of mv_cost index.
Bug: b/72510002
Test: poc provided in the bug.
Change-Id: Ia8883ad7bd073377e95eeaad2a5ddfd3a55cd53b
Diffstat (limited to 'libvpx')
-rw-r--r-- | libvpx/vp8/encoder/mcomp.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/libvpx/vp8/encoder/mcomp.c b/libvpx/vp8/encoder/mcomp.c index 970120f3b..b4a49a3b1 100644 --- a/libvpx/vp8/encoder/mcomp.c +++ b/libvpx/vp8/encoder/mcomp.c @@ -34,19 +34,22 @@ int vp8_mv_bit_cost(int_mv *mv, int_mv *ref, int *mvcost[2], int Weight) { * NEAREST for subsequent blocks. The "Weight" parameter allows, to a * limited extent, for some account to be taken of these factors. */ - return ((mvcost[0][(mv->as_mv.row - ref->as_mv.row) >> 1] + - mvcost[1][(mv->as_mv.col - ref->as_mv.col) >> 1]) * - Weight) >> - 7; + const int mv_idx_row = + clamp((mv->as_mv.row - ref->as_mv.row) >> 1, 0, MVvals); + const int mv_idx_col = + clamp((mv->as_mv.col - ref->as_mv.col) >> 1, 0, MVvals); + return ((mvcost[0][mv_idx_row] + mvcost[1][mv_idx_col]) * Weight) >> 7; } static int mv_err_cost(int_mv *mv, int_mv *ref, int *mvcost[2], int error_per_bit) { /* Ignore mv costing if mvcost is NULL */ if (mvcost) { - return ((mvcost[0][(mv->as_mv.row - ref->as_mv.row) >> 1] + - mvcost[1][(mv->as_mv.col - ref->as_mv.col) >> 1]) * - error_per_bit + + const int mv_idx_row = + clamp((mv->as_mv.row - ref->as_mv.row) >> 1, 0, MVvals); + const int mv_idx_col = + clamp((mv->as_mv.col - ref->as_mv.col) >> 1, 0, MVvals); + return ((mvcost[0][mv_idx_row] + mvcost[1][mv_idx_col]) * error_per_bit + 128) >> 8; } |