From 13ada41172142f2fd9f0906f615a00ea623a11ca Mon Sep 17 00:00:00 2001
From: Andrew Murray <3112309+radarhere@users.noreply.github.com>
Date: Mon, 22 Jun 2026 10:34:18 +1000
Subject: [PATCH] Calculate JPEG2000 total_component_width for each tile in
 isolation (#9704)

---
 src/libImaging/Jpeg2KDecode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: pillow-11.3.0/src/libImaging/Jpeg2KDecode.c
===================================================================
--- pillow-11.3.0.orig/src/libImaging/Jpeg2KDecode.c
+++ pillow-11.3.0/src/libImaging/Jpeg2KDecode.c
@@ -644,7 +644,6 @@ j2k_decode_entry(Imaging im, ImagingCode
     size_t tile_bytes = 0;
     unsigned n, tile_height, tile_width;
     int subsampling;
-    int total_component_width = 0;
 
     stream = opj_stream_create(BUFFER_SIZE, OPJ_TRUE);
 
@@ -850,6 +849,7 @@ j2k_decode_entry(Imaging im, ImagingCode
          a, and then a malicious file could have a smaller tile_bytes
         */
 
+        int total_component_width = 0;
         for (n = 0; n < tile_info.nb_comps; n++) {
             // see csize /acsize calcs
             int csize = (image->comps[n].prec + 7) >> 3;
