Detect when we have read beyond the end of buffer.

Add the aom_reader_has_overflowed() function.

Abort the decode_tile() process if the entropy decoder has read beyond
the end of the data buffer.

BUG=oss-fuzz:9663

Change-Id: I61b91d171fdbee0928da7b2ac05412327c299262
diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c
index c7eb2ae..3f5afe9 100644
--- a/av1/decoder/decodeframe.c
+++ b/av1/decoder/decodeframe.c
@@ -2771,15 +2771,11 @@
 }
 
 static int check_trailing_bits_after_symbol_coder(aom_reader *r) {
+  if (aom_reader_has_overflowed(r)) return -1;
+
   uint32_t nb_bits = aom_reader_tell(r);
   uint32_t nb_bytes = (nb_bits + 7) >> 3;
-
-  const uint8_t *p_begin = aom_reader_find_begin(r);
-  const uint8_t *p_end = aom_reader_find_end(r);
-
-  // It is legal to have no padding bytes (nb_bytes == p_end - p_begin).
-  if ((ptrdiff_t)nb_bytes > p_end - p_begin) return -1;
-  const uint8_t *p = p_begin + nb_bytes;
+  const uint8_t *p = aom_reader_find_begin(r) + nb_bytes;
 
   // aom_reader_tell() returns 1 for a newly initialized decoder, and the
   // return value only increases as values are decoded. So nb_bits > 0, and
@@ -2789,6 +2785,7 @@
   if ((last_byte & (2 * pattern - 1)) != pattern) return -1;
 
   // Make sure that all padding bytes are zero as required by the spec.
+  const uint8_t *p_end = aom_reader_find_end(r);
   while (p < p_end) {
     if (*p != 0) return -1;
     p++;
@@ -2842,6 +2839,11 @@
       // Bit-stream parsing and decoding of the superblock
       decode_partition(pbi, td, mi_row, mi_col, td->bit_reader,
                        cm->seq_params.sb_size, 0x3);
+
+      if (aom_reader_has_overflowed(td->bit_reader)) {
+        aom_merge_corrupted_flag(&td->xd.corrupted, 1);
+        return;
+      }
     }
   }