From 3d53ed21cadb612e3b9828ccf116227e6a6ce21a Mon Sep 17 00:00:00 2001
From: Kimball Thurston <kdt3rd@gmail.com>
Date: Tue, 28 Oct 2025 02:49:19 +1300
Subject: [PATCH] Fix issues with negative coordinates and sampling != 0
 (#2160)

* remove unused variable

Signed-off-by: Kimball Thurston <kdt3rd@gmail.com>

* allow a single line when positions are negative with large y sampling > height

Signed-off-by: Kimball Thurston <kdt3rd@gmail.com>

---------

Signed-off-by: Kimball Thurston <kdt3rd@gmail.com>
---
 src/lib/OpenEXRCore/internal_util.h | 5 +++--
 src/lib/OpenEXRCore/parse_header.c  | 1 -
 2 files changed, 3 insertions(+), 3 deletions(-)

Index: openexr-3.2.2/src/lib/OpenEXRCore/internal_util.h
===================================================================
--- openexr-3.2.2.orig/src/lib/OpenEXRCore/internal_util.h
+++ openexr-3.2.2/src/lib/OpenEXRCore/internal_util.h
@@ -31,10 +31,10 @@ compute_sampled_lines (int height, int y
         else
             start = start_y;
         end = start_y + height - 1;
-        end -= (end % y_sampling);
+        end -= (end < 0 ? -end : end) % y_sampling;
 
         if (start > end)
-            nlines = 0;
+            nlines = start == start_y ? 1 : 0;
         else
             nlines = (end - start) / y_sampling + 1;
     }
