Change av1_get_uniform_tile_size() to return bool

Not all the callers of av1_get_uniform_tile_size() have the jmp_buf set
up, so av1_get_uniform_tile_size() can't call aom_internal_error().
Change av1_get_uniform_tile_size() to return bool to indicate
success/failure.

Bug: oss-fuzz:67058
Bug: oss-fuzz:67161
Change-Id: I92f9ee78c28b2a4fbe71d486569959b30d1ff76a
diff --git a/av1/av1_dx_iface.c b/av1/av1_dx_iface.c
index e05a705..6ab04f6 100644
--- a/av1/av1_dx_iface.c
+++ b/av1/av1_dx_iface.c
@@ -866,7 +866,9 @@
   if (pbi->ext_tile_debug && tiles->single_tile_decoding &&
       pbi->dec_tile_row >= 0) {
     int tile_width, tile_height;
-    av1_get_uniform_tile_size(cm, &tile_width, &tile_height);
+    if (!av1_get_uniform_tile_size(cm, &tile_width, &tile_height)) {
+      return NULL;
+    }
     const int tile_row = AOMMIN(pbi->dec_tile_row, tiles->rows - 1);
     const int mi_row = tile_row * tile_height;
     const int ssy = ctx->img.y_chroma_shift;
@@ -885,7 +887,9 @@
   if (pbi->ext_tile_debug && tiles->single_tile_decoding &&
       pbi->dec_tile_col >= 0) {
     int tile_width, tile_height;
-    av1_get_uniform_tile_size(cm, &tile_width, &tile_height);
+    if (!av1_get_uniform_tile_size(cm, &tile_width, &tile_height)) {
+      return NULL;
+    }
     const int tile_col = AOMMIN(pbi->dec_tile_col, tiles->cols - 1);
     const int mi_col = tile_col * tile_width;
     const int ssx = ctx->img.x_chroma_shift;
@@ -1429,7 +1433,9 @@
           (FrameWorkerData *)worker->data1;
       const AV1_COMMON *const cm = &frame_worker_data->pbi->common;
       int tile_width, tile_height;
-      av1_get_uniform_tile_size(cm, &tile_width, &tile_height);
+      if (!av1_get_uniform_tile_size(cm, &tile_width, &tile_height)) {
+        return AOM_CODEC_CORRUPT_FRAME;
+      }
       *tile_size = ((tile_width * MI_SIZE) << 16) + tile_height * MI_SIZE;
       return AOM_CODEC_OK;
     } else {
diff --git a/av1/common/tile_common.c b/av1/common/tile_common.c
index 31ab9c8..b073759 100644
--- a/av1/common/tile_common.c
+++ b/av1/common/tile_common.c
@@ -177,7 +177,7 @@
                            cm->seq_params->mib_size_log2);
 }
 
-void av1_get_uniform_tile_size(const AV1_COMMON *cm, int *w, int *h) {
+bool av1_get_uniform_tile_size(const AV1_COMMON *cm, int *w, int *h) {
   const CommonTileParams *const tiles = &cm->tiles;
   if (tiles->uniform_spacing) {
     *w = tiles->width;
@@ -189,9 +189,7 @@
       const int tile_w = tile_width_sb * cm->seq_params->mib_size;
       // ensure all tiles have same dimension
       if (i != 0 && tile_w != *w) {
-        aom_internal_error(cm->error, AOM_CODEC_UNSUP_BITSTREAM,
-                           "tile %d does not have the same width: %d != %d", i,
-                           tile_w, *w);
+        return false;
       }
       *w = tile_w;
     }
@@ -202,13 +200,12 @@
       const int tile_h = tile_height_sb * cm->seq_params->mib_size;
       // ensure all tiles have same dimension
       if (i != 0 && tile_h != *h) {
-        aom_internal_error(cm->error, AOM_CODEC_UNSUP_BITSTREAM,
-                           "tile %d does not have the same height: %d != %d", i,
-                           tile_h, *h);
+        return false;
       }
       *h = tile_h;
     }
   }
+  return true;
 }
 
 int av1_is_min_tile_width_satisfied(const AV1_COMMON *cm) {
diff --git a/av1/common/tile_common.h b/av1/common/tile_common.h
index 851125f..203c354 100644
--- a/av1/common/tile_common.h
+++ b/av1/common/tile_common.h
@@ -12,12 +12,14 @@
 #ifndef AOM_AV1_COMMON_TILE_COMMON_H_
 #define AOM_AV1_COMMON_TILE_COMMON_H_
 
+#include <stdbool.h>
+
+#include "config/aom_config.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-#include "config/aom_config.h"
-
 struct AV1Common;
 struct SequenceHeader;
 struct CommonTileParams;
@@ -51,7 +53,8 @@
 #define MAX_TILE_AREA_LEVEL_7_AND_ABOVE (4096 * 4608)
 #endif
 
-void av1_get_uniform_tile_size(const struct AV1Common *cm, int *w, int *h);
+// Returns true on success, false on failure.
+bool av1_get_uniform_tile_size(const struct AV1Common *cm, int *w, int *h);
 void av1_get_tile_limits(struct AV1Common *const cm);
 void av1_calculate_tile_cols(const struct SequenceHeader *const seq_params,
                              int cm_mi_rows, int cm_mi_cols,
diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c
index 4e3fc45..e654230 100644
--- a/av1/decoder/decodeframe.c
+++ b/av1/decoder/decodeframe.c
@@ -2294,7 +2294,11 @@
     const int tile_col_size_bytes = pbi->tile_col_size_bytes;
     const int tile_size_bytes = pbi->tile_size_bytes;
     int tile_width, tile_height;
-    av1_get_uniform_tile_size(cm, &tile_width, &tile_height);
+    if (!av1_get_uniform_tile_size(cm, &tile_width, &tile_height)) {
+      aom_internal_error(
+          &pbi->error, AOM_CODEC_CORRUPT_FRAME,
+          "Not all the tiles in the tile list have the same size.");
+    }
     const int tile_copy_mode =
         ((AOMMAX(tile_width, tile_height) << MI_SIZE_LOG2) <= 256) ? 1 : 0;
     // Read tile column sizes for all columns (we need the last tile buffer)
diff --git a/av1/decoder/obu.c b/av1/decoder/obu.c
index 992ed75..b644402 100644
--- a/av1/decoder/obu.c
+++ b/av1/decoder/obu.c
@@ -501,7 +501,10 @@
   }
 
   int tile_width, tile_height;
-  av1_get_uniform_tile_size(cm, &tile_width, &tile_height);
+  if (!av1_get_uniform_tile_size(cm, &tile_width, &tile_height)) {
+    pbi->error.error_code = AOM_CODEC_CORRUPT_FRAME;
+    return 0;
+  }
   const int tile_width_in_pixels = tile_width * MI_SIZE;
   const int tile_height_in_pixels = tile_height * MI_SIZE;