Fix edge case when downsizing to one.
authorBohan Li <bohanli@google.com>
Fri, 1 Dec 2023 00:18:25 +0000 (16:18 -0800)
committerJerome Jiang <jianj@google.com>
Wed, 6 Dec 2023 21:22:24 +0000 (16:22 -0500)
BUG: b/310329177
Change-Id: I2ebf4165adbc7351d6cc73554827812dedc4d362
(cherry picked from commit a9f1bfdb8e93a742da9a14d4a9d3b1d847edd70d)

test/encode_api_test.cc
vp9/encoder/vp9_resize.c

index 25c8d76..3dfcc2e 100644 (file)
@@ -763,6 +763,25 @@ TEST(EncodeAPI, Buganizer312656387) {
   encoder.Encode(false);
 }
 
+// This is a test case from clusterfuzz: based on b/310329177.
+// Encode a few frames with multiple change config call
+// with different frame size.
+TEST(EncodeAPI, Buganizer310329177) {
+  VP9Encoder encoder(6);
+
+  // Set initial config.
+  encoder.Configure(10, 41, 1, VPX_VBR, VPX_DL_REALTIME);
+
+  // Encode first frame.
+  encoder.Encode(true);
+
+  // Change config.
+  encoder.Configure(16, 1, 1, VPX_VBR, VPX_DL_REALTIME);
+
+  // Encode 2nd frame with new config, set delta frame.
+  encoder.Encode(false);
+}
+
 class EncodeApiGetTplStatsTest
     : public ::libvpx_test::EncoderTest,
       public ::testing::TestWithParam<const libvpx_test::CodecFactory *> {
index 7486dee..ca55ec9 100644 (file)
@@ -360,6 +360,12 @@ static int get_down2_steps(int in_length, int out_length) {
   while ((proj_in_length = get_down2_length(in_length, 1)) >= out_length) {
     ++steps;
     in_length = proj_in_length;
+    if (in_length == 1) {
+      // Special case: we break because any further calls to get_down2_length()
+      // with be with length == 1, which return 1, resulting in an infinite
+      // loop.
+      break;
+    }
   }
   return steps;
 }