From c7258b810b520cfa6fdb14b17b509aa31bd70791 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 10 Mar 2026 10:32:13 -0700
Subject: [PATCH] Fixed potential buffer overflow in tRNS handling
Closes https://github.com/libsdl-org/SDL_image/pull/704
(cherry picked from commit 19cc7cdb1e30554d3bf4f4526a21a8f57b861279)
---
src/IMG_libpng.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/IMG_libpng.c b/src/IMG_libpng.c
index 365565a6..08ac6a12 100644
--- a/src/IMG_libpng.c
+++ b/src/IMG_libpng.c
@@ -1341,7 +1341,7 @@ bool IMG_CreateAPNGAnimationDecoder(IMG_AnimationDecoder *decoder, SDL_Propertie
} else if (SDL_memcmp(chunk_type, "tRNS", 4) == 0) {
if (ctx->palette) {
- int num_trans = SDL_min((int)chunk_size, ctx->palette->ncolors);
+ int num_trans = SDL_min((int)chunk_length, ctx->palette->ncolors);
for (int i = 0; i < num_trans; i++) {
ctx->palette->colors[i].a = chunk_data[i];
}