Avoid out of boundary read in region array

Validate the region array index to avoid out of boundary read.

Change-Id: I2060af4212e44a6214b783ee37b4bae9928b6004
(cherry picked from commit 3dd15c7e41a16ff74216277697fb28fab312506e)
diff --git a/av1/encoder/pass2_strategy.c b/av1/encoder/pass2_strategy.c
index 482e260..5267f57 100644
--- a/av1/encoder/pass2_strategy.c
+++ b/av1/encoder/pass2_strategy.c
@@ -2082,11 +2082,11 @@
       // reset pointers to the shrinked location
       twopass->stats_in = start_pos + cur_last;
       cur_start = cur_last;
-      if (regions[find_regions_index(regions, num_regions,
-                                     cur_start + 1 + offset)]
-              .type == SCENECUT_REGION) {
-        cur_start++;
-      }
+      int cur_region_idx =
+          find_regions_index(regions, num_regions, cur_start + 1 + offset);
+      if (cur_region_idx >= 0)
+        if (regions[cur_region_idx].type == SCENECUT_REGION) cur_start++;
+
       i = cur_last;
 
       if (cut_here > 1 && cur_last == ori_last) break;