From 899585ebe9a1e8e3ba408ac0b1652e14d8d6eaaf Mon Sep 17 00:00:00 2001
From: Jim Bankoski <jimbankoski@google.com>
Date: Mon, 28 Jul 2014 08:37:25 -0700
Subject: [PATCH] Fix reference frame size restrictions.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The issue was introduced by commit g9f37d14 with adding explicit
restrictions on reference-frame scale factors. The restriction
is checked against aligned-by-8 frame dimensions, not against
original ones. So, for example, frame of 35×35 actually can refer
to frame of 70×70, but the new check won't allow this. It will
compare 35 vs 72 (not 70), so 2x downscale limit will be exceeded.

Change-Id: Ic663693034440f64ac8312cbff9e1e773a921060
---
 test/test-data.sha1           | 2 ++
 test/test.mk                  | 2 ++
 test/test_vectors.cc          | 2 +-
 vp9/decoder/vp9_decodeframe.c | 4 ++--
 4 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/test/test-data.sha1 b/test/test-data.sha1
index b7a8f3f2b1..98ac0e670c 100644
--- a/test/test-data.sha1
+++ b/test/test-data.sha1
@@ -678,3 +678,5 @@ eb438c6540eb429f74404eedfa3228d409c57874  desktop_640_360_30.yuv
 edd86a1f5e62fd9da9a9d46078247759c2638009  tacomasmallcameramovement_640_480_30.yuv
 9a70e8b7d14fba9234d0e51dce876635413ce444  thaloundeskmtg_640_480_30.yuv
 e7d315dbf4f3928779e0dc624311196d44491d32  niklas_1280_720_30.yuv
+c77e4a26616add298a05dd5d12397be22c0e40c5  vp90-2-18-resize.ivf
+c77e4a26616add298a05dd5d12397be22c0e40c5  vp90-2-18-resize.ivf
diff --git a/test/test.mk b/test/test.mk
index 4355237bbb..53d40572a9 100644
--- a/test/test.mk
+++ b/test/test.mk
@@ -782,6 +782,8 @@ LIBVPX_TEST_DATA-$(CONFIG_VP9_DECODER) += vp90-2-16-intra-only.webm
 LIBVPX_TEST_DATA-$(CONFIG_VP9_DECODER) += vp90-2-16-intra-only.webm.md5
 LIBVPX_TEST_DATA-$(CONFIG_VP9_DECODER) += vp90-2-17-show-existing-frame.webm
 LIBVPX_TEST_DATA-$(CONFIG_VP9_DECODER) += vp90-2-17-show-existing-frame.webm.md5
+LIBVPX_TEST_DATA-$(CONFIG_VP9_DECODER) += vp90-2-18-resize.ivf
+LIBVPX_TEST_DATA-$(CONFIG_VP9_DECODER) += vp90-2-18-resize.ivf.md5
 LIBVPX_TEST_DATA-$(CONFIG_VP9_DECODER) += vp91-2-04-yuv444.webm
 LIBVPX_TEST_DATA-$(CONFIG_VP9_DECODER) += vp91-2-04-yuv444.webm.md5
 
diff --git a/test/test_vectors.cc b/test/test_vectors.cc
index 4ea4b9dab7..dbdbdd6f9c 100644
--- a/test/test_vectors.cc
+++ b/test/test_vectors.cc
@@ -181,7 +181,7 @@ const char *const kVP9TestVectors[] = {
   "vp90-2-14-resize-fp-tiles-8-2.webm", "vp90-2-14-resize-fp-tiles-8-4.webm",
   "vp90-2-15-segkey.webm", "vp90-2-15-segkey_adpq.webm",
   "vp90-2-16-intra-only.webm", "vp90-2-17-show-existing-frame.webm",
-  "vp91-2-04-yuv444.webm",
+  "vp90-2-18-resize.ivf", "vp91-2-04-yuv444.webm",
 };
 const int kNumVP9TestVectors = NELEMENTS(kVP9TestVectors);
 #endif  // CONFIG_VP9_DECODER
diff --git a/vp9/decoder/vp9_decodeframe.c b/vp9/decoder/vp9_decodeframe.c
index cc6f955370..a448bd2b46 100644
--- a/vp9/decoder/vp9_decodeframe.c
+++ b/vp9/decoder/vp9_decodeframe.c
@@ -688,8 +688,8 @@ static void setup_frame_size_with_refs(VP9_COMMON *cm,
   // has valid dimensions.
   for (i = 0; i < REFS_PER_FRAME; ++i) {
     RefBuffer *const ref_frame = &cm->frame_refs[i];
-    has_valid_ref_frame |= valid_ref_frame_size(ref_frame->buf->y_width,
-                                                ref_frame->buf->y_height,
+    has_valid_ref_frame |= valid_ref_frame_size(ref_frame->buf->y_crop_width,
+                                                ref_frame->buf->y_crop_height,
                                                 width, height);
   }
   if (!has_valid_ref_frame)
-- 
GitLab