SDL_image: Fixed loading of XCF tile layers

From 698f2cf4eb6fa8e5d2e803b85d418af5cb9df47f Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 2 Aug 2023 07:57:52 -0700
Subject: [PATCH] Fixed loading of XCF tile layers

The length that's passed in is the maximum size for the tile, the RLE encoded data may be shorter.
---
 src/IMG_xcf.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/IMG_xcf.c b/src/IMG_xcf.c
index bc7705f5..0f14882b 100644
--- a/src/IMG_xcf.c
+++ b/src/IMG_xcf.c
@@ -561,12 +561,12 @@ static unsigned char * load_xcf_tile_rle (SDL_RWops * src, Uint64 len, int bpp,
     return NULL;
   }
 
-  t = load = (unsigned char *) SDL_malloc ((size_t)len);
+  t = load = (unsigned char *) SDL_calloc (1, (size_t)len);
   if (load == NULL)
     return NULL;
 
   read = SDL_RWread(src, load, len);
-  if (read < 0 || (Uint64)read != len) {
+  if (read <= 0) {
     SDL_free(load);
     return NULL;
   }
@@ -587,7 +587,7 @@ static unsigned char * load_xcf_tile_rle (SDL_RWops * src, Uint64 len, int bpp,
           t += 2;
         }
 
-        if (((size_t) (t - load) + length) >= len) {
+        if (((size_t) (t - load) + length) >= read) {
           break;  /* bogus data */
         } else if (length > size) {
           break;  /* bogus data */
@@ -606,7 +606,7 @@ static unsigned char * load_xcf_tile_rle (SDL_RWops * src, Uint64 len, int bpp,
           t += 2;
         }
 
-        if (((size_t) (t - load)) >= len) {
+        if (((size_t) (t - load)) >= read) {
           break;  /* bogus data */
         } else if (length > size) {
           break;  /* bogus data */