SDL_image: Fixed chunk alignment in the ANI decoder (fd42e)

From fd42eed81328b3e2c9cdf99a49749ce5700c6975 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 23 Apr 2026 13:33:09 -0700
Subject: [PATCH] Fixed chunk alignment in the ANI decoder

Fixes https://github.com/libsdl-org/SDL_image/issues/730

(cherry picked from commit 48fca18af35efc2938f1be2c3e5e42f23f230fe5)
---
 src/IMG_ani.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/IMG_ani.c b/src/IMG_ani.c
index a494aec35..5cf41c4de 100644
--- a/src/IMG_ani.c
+++ b/src/IMG_ani.c
@@ -252,6 +252,12 @@ static bool ParseInfoList(IMG_AnimationParseContext *parse, Uint32 list_size)
                 return false;
             }
         }
+        if (size & 1) {
+            ++size;
+            if (SDL_SeekIO(src, 1, SDL_IO_SEEK_CUR) < 0) {
+                return false;
+            }
+        }
         offset += size;
     }
     return true;
@@ -292,6 +298,12 @@ static bool ParseFrameList(IMG_AnimationParseContext *parse, Uint32 list_size)
         if (SDL_SeekIO(src, size, SDL_IO_SEEK_CUR) < 0) {
             return false;
         }
+        if (size & 1) {
+            ++size;
+            if (SDL_SeekIO(src, 1, SDL_IO_SEEK_CUR) < 0) {
+                return false;
+            }
+        }
         offset += size;
     }
     if (frame_count < anih->frames) {
@@ -435,6 +447,12 @@ bool IMG_CreateANIAnimationDecoder(IMG_AnimationDecoder *decoder, SDL_Properties
                 goto done;
             }
         }
+        if (size & 1) {
+            ++size;
+            if (SDL_SeekIO(decoder->src, 1, SDL_IO_SEEK_CUR) < 0) {
+                goto done;
+            }
+        }
         offset += size;
     }