SDL_image: Fixed RIFF chunk alignment in the ANI save codepath

From b5ae5e2336b510e77891d6a7292f852b4b38a7d0 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 23 Apr 2026 16:08:52 -0700
Subject: [PATCH] Fixed RIFF chunk alignment in the ANI save codepath

---
 src/IMG_ani.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/IMG_ani.c b/src/IMG_ani.c
index 5cf41c4d..b8d84d6e 100644
--- a/src/IMG_ani.c
+++ b/src/IMG_ani.c
@@ -556,7 +556,15 @@ static bool SaveChunkSize(SDL_IOStream *dst, Sint64 offset)
     if (!SDL_WriteU32LE(dst, size)) {
         return false;
     }
-    return SDL_SeekIO(dst, here, SDL_IO_SEEK_SET);
+    if (!SDL_SeekIO(dst, here, SDL_IO_SEEK_SET)) {
+        return false;
+    }
+    if (size & 1) {
+        if (!SDL_WriteU8(dst, 0)) {
+            return false;
+        }
+    }
+    return true;
 }
 
 static bool WriteIconFrame(SDL_Surface *surface, SDL_IOStream *dst)
@@ -587,6 +595,9 @@ static bool WriteAnimInfo(IMG_AnimationEncoderContext *ctx, SDL_IOStream *dst)
         result &= SDL_WriteU32LE(dst, RIFF_FOURCC('I', 'N', 'A', 'M'));
         result &= SDL_WriteU32LE(dst, size);
         result &= (SDL_WriteIO(dst, ctx->title, size) == size);
+        if (size & 1) {
+            result &= SDL_WriteU8(dst, 0);
+        }
     }
 
     if (ctx->author) {
@@ -594,6 +605,9 @@ static bool WriteAnimInfo(IMG_AnimationEncoderContext *ctx, SDL_IOStream *dst)
         result &= SDL_WriteU32LE(dst, RIFF_FOURCC('I', 'A', 'R', 'T'));
         result &= SDL_WriteU32LE(dst, size);
         result &= (SDL_WriteIO(dst, ctx->author, size) == size);
+        if (size & 1) {
+            result &= SDL_WriteU8(dst, 0);
+        }
     }
 
     result &= SaveChunkSize(dst, list_size_offset);