SDL_image: IMG_avif: fixed header size type, and limit it to INT_MAX for now.

From 47275ee68c51d17a19810fd298df16223ad60859 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Tue, 17 May 2022 17:02:02 +0300
Subject: [PATCH] IMG_avif: fixed header size type, and limit it to INT_MAX for
 now.

---
 IMG_avif.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/IMG_avif.c b/IMG_avif.c
index f2d75c6..bc00aa3 100644
--- a/IMG_avif.c
+++ b/IMG_avif.c
@@ -26,6 +26,7 @@
 #ifdef LOAD_AVIF
 
 #include <avif/avif.h>
+#include <limits.h> /* for INT_MAX */
 
 
 static struct {
@@ -87,7 +88,7 @@ void IMG_QuitAVIF()
 static SDL_bool ReadAVIFHeader(SDL_RWops *src, Uint8 **header_data, size_t *header_size)
 {
     Uint8 magic[16];
-    size_t size;
+    Uint64 size;
     size_t read = 0;
     Uint8 *data;
 
@@ -124,6 +125,9 @@ static SDL_bool ReadAVIFHeader(SDL_RWops *src, Uint8 **header_data, size_t *head
                 ((size_t)magic[15] << 0));
     }
 
+    if (size > INT_MAX) {
+        return SDL_FALSE;
+    }
     if (size <= read) {
         return SDL_FALSE;
     }
@@ -140,7 +144,7 @@ static SDL_bool ReadAVIFHeader(SDL_RWops *src, Uint8 **header_data, size_t *head
         return SDL_FALSE;
     }
     *header_data = data;
-    *header_size = size;
+    *header_size = (size_t)size;
     return SDL_TRUE;
 }