You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by am...@apache.org on 2026/05/18 15:54:49 UTC

(sis) 07/07: fix(Image): Prevent reshaped image to return data outside its domain

This is an automated email from the ASF dual-hosted git repository.

alexismanin pushed a commit to branch fix/image-tile-matrix-get-tile
in repository https://gitbox.apache.org/repos/asf/sis.git

commit 3f10b8f44ae15733cf7c08e908d11aefc53315d3
Author: Alexis Manin <al...@geomatys.com>
AuthorDate: Mon May 18 17:54:22 2026 +0200

    fix(Image): Prevent reshaped image to return data outside its domain
    
    Avoid user to be able to access areas in source images that are not accesible from current reshaped image
---
 .../main/org/apache/sis/image/internal/shared/ReshapedImage.java   | 4 ++++
 .../org/apache/sis/image/internal/shared/ReshapedImageTest.java    | 7 +++++++
 2 files changed, 11 insertions(+)

diff --git a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/internal/shared/ReshapedImage.java b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/internal/shared/ReshapedImage.java
index 17bebfaab5..778800f1f7 100644
--- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/internal/shared/ReshapedImage.java
+++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/image/internal/shared/ReshapedImage.java
@@ -95,8 +95,12 @@ public final class ReshapedImage extends PlanarImage {
             final var r = (ReshapedImage) source;
             offsetX = addExact(offsetX, r.offsetX);
             offsetY = addExact(offsetY, r.offsetY);
+            if (offsetX < r.offsetX || offsetY < r.offsetY || offsetX + width > r.offsetX + r.width || offsetY + height > r.offsetY + r.height) {
+                throw new IllegalArgumentException("It is forbidden to try to expand access over source image");
+            }
             source  = r.source;
         }
+
         this.source   = source;
         this.offsetX  = toIntExact(offsetX);
         this.offsetY  = toIntExact(offsetY);
diff --git a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/image/internal/shared/ReshapedImageTest.java b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/image/internal/shared/ReshapedImageTest.java
index 10884f8d3b..1407f6bf85 100644
--- a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/image/internal/shared/ReshapedImageTest.java
+++ b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/image/internal/shared/ReshapedImageTest.java
@@ -221,5 +221,12 @@ public final class ReshapedImageTest extends TestCase {
                 { 400, 401 },
                 { 410, 411 }
         });
+
+        try {
+            ReshapedImage.singleTile(lastTile, 1, 0);
+            fail("Tile data should not be accessible from previously restricted reshaped image");
+        } catch (IllegalArgumentException e) {
+            // Expected
+        }
     }
 }