Consider SEQ_LEVEL_MAX for max tile size.

Also replace an assertion with proper error handling.

Bug: oss-fuzz:50620
Bug: aomedia:2871

Change-Id: Idfdf1636800ba08afbd31b20ff9f406fbd3a48e9
diff --git a/av1/common/tile_common.c b/av1/common/tile_common.c
index 71eaf01..569acbc 100644
--- a/av1/common/tile_common.c
+++ b/av1/common/tile_common.c
@@ -42,11 +42,17 @@
 
   bool use_level_7_above = false;
   for (int i = 0; i < seq_params->operating_points_cnt_minus_1 + 1; i++) {
-    if (seq_params->seq_level_idx[i] >= SEQ_LEVEL_7_0 &&
-        seq_params->seq_level_idx[i] <= SEQ_LEVEL_8_3) {
-      // Currently it is assumed that levels 7.x/8.x are either used for all
+    if ((seq_params->seq_level_idx[i] >= SEQ_LEVEL_7_0 &&
+         seq_params->seq_level_idx[i] <= SEQ_LEVEL_8_3) ||
+        seq_params->seq_level_idx[i] == SEQ_LEVEL_MAX) {
+      // Currently it is assumed that levels >= 7.0 are either used for all
       // operating points, or none of them.
-      assert(i == 0 || use_level_7_above);
+      if (i != 0 && !use_level_7_above) {
+        aom_internal_error(
+            cm->error, AOM_CODEC_UNSUP_BITSTREAM,
+            "The levels of the operating points should be either all smaller "
+            "than 7.0 or all larger than or equal to 7.0");
+      }
       use_level_7_above = true;
     }
   }
diff --git a/av1/encoder/level.c b/av1/encoder/level.c
index 4d17142..41e47be 100644
--- a/av1/encoder/level.c
+++ b/av1/encoder/level.c
@@ -1016,9 +1016,11 @@
       break;
     }
 
-    const int max_tile_size = (level >= SEQ_LEVEL_7_0 && level <= SEQ_LEVEL_8_3)
-                                  ? MAX_TILE_AREA_LEVEL_7_AND_ABOVE
-                                  : MAX_TILE_AREA;
+    const int max_tile_size =
+        ((level >= SEQ_LEVEL_7_0 && level <= SEQ_LEVEL_8_3) ||
+         level == SEQ_LEVEL_MAX)
+            ? MAX_TILE_AREA_LEVEL_7_AND_ABOVE
+            : MAX_TILE_AREA;
     if (level_stats->max_tile_size > max_tile_size) {
       fail_id = TILE_TOO_LARGE;
       break;