From c41a2fc901608c912f73bd7a0e53b3c9ccb58074 Mon Sep 17 00:00:00 2001
From: Peter Hillman <peterh@wetafx.co.nz>
Date: Thu, 30 Oct 2025 08:04:36 +1300
Subject: [PATCH] ImfCheckFile: handle partial deep tiles

Signed-off-by: Peter Hillman <peterh@wetafx.co.nz>
---
 src/lib/OpenEXRUtil/ImfCheckFile.cpp | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

Index: openexr-3.2.2/src/lib/OpenEXRUtil/ImfCheckFile.cpp
===================================================================
--- openexr-3.2.2.orig/src/lib/OpenEXRUtil/ImfCheckFile.cpp
+++ openexr-3.2.2/src/lib/OpenEXRUtil/ImfCheckFile.cpp
@@ -654,15 +654,24 @@ readDeepTile (T& in, bool reduceMemory,
                             try
                             {
 
+
                                 in.readPixelSampleCounts (
                                     x, y, x, y, xlevel, ylevel);
 
                                 size_t bufferSize = 0;
                                 size_t fileBufferSize = 0;
 
-                                for (int ty = 0; ty < tileHeight; ++ty)
+                                Box2i tileRange =
+                                    in.dataWindowForTile (x, y, xlevel, ylevel);
+
+                                int thisTileWidth =
+                                    tileRange.max.x - tileRange.min.x + 1;
+                                int thisTileHeight =
+                                    tileRange.max.y - tileRange.min.y + 1;
+
+                                for (int ty = 0; ty < thisTileHeight; ++ty)
                                 {
-                                    for (int tx = 0; tx < tileWidth; ++tx)
+                                    for (int tx = 0; tx < thisTileWidth; ++tx)
                                     {
                                         fileBufferSize += channelCount *
                                                 localSampleCount[ty][tx];
@@ -689,9 +698,10 @@ readDeepTile (T& in, bool reduceMemory,
                                     pixelBuffer.resize (bufferSize);
                                     size_t bufferIndex = 0;
 
-                                    for (int ty = 0; ty < tileHeight; ++ty)
+                                    for (int ty = 0; ty < thisTileHeight; ++ty)
                                     {
-                                        for (int tx = 0; tx < tileWidth; ++tx)
+                                        for (int tx = 0; tx < thisTileWidth;
+                                             ++tx)
                                         {
                                             if (!reduceMemory ||
                                                 localSampleCount[ty][tx] *
