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

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new 021178f9d9 Avoid a stack overflow when `getDomain(…)` is invoked on a 
chain of transforms which contains a `WrapAroundTransform`.
021178f9d9 is described below

commit 021178f9d9b5f779aade1898bccb8f6edc3b39d4
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Sun Jul 10 22:14:47 2022 +0200

    Avoid a stack overflow when `getDomain(…)` is invoked on a chain of 
transforms which contains a `WrapAroundTransform`.
---
 .../referencing/operation/transform/DomainDefinition.java   | 11 ++++++++++-
 .../operation/transform/WraparoundTransform.java            | 13 +++++++++----
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git 
a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DomainDefinition.java
 
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DomainDefinition.java
index 868536b017..09de473d7b 100644
--- 
a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DomainDefinition.java
+++ 
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/DomainDefinition.java
@@ -179,7 +179,16 @@ public class DomainDefinition {
             estimateOnInverse(ct.transform2);
             estimateOnInverse(ct.transform1, ct.transform2);
         } else {
-            estimate(inverse.inverse());
+            final MathTransform forward = inverse.inverse();
+            if (forward instanceof ConcatenatedTransform) {
+                final ConcatenatedTransform ct = (ConcatenatedTransform) 
forward;
+                final MathTransform transform1 = ct.transform2.inverse();
+                final MathTransform transform2 = ct.transform1.inverse();
+                estimateOnInverse(transform2);
+                estimateOnInverse(transform1, transform2);
+            } else {
+                estimate(forward);
+            }
         }
     }
 
diff --git 
a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/WraparoundTransform.java
 
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/WraparoundTransform.java
index d730226945..5cb4253d44 100644
--- 
a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/WraparoundTransform.java
+++ 
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/WraparoundTransform.java
@@ -223,16 +223,21 @@ public class WraparoundTransform extends 
AbstractMathTransform implements Serial
          * Since we are going to apply a `-targetMedian` translation before 
the `WraparoundTransform`, the
          * `sourceMedian` used for computing the inverse of that transform 
must have the same translation.
          */
-        MathTransform tr = new WraparoundTransform(dimension, 
wraparoundDimension, period, sourceMedian - targetMedian);
-        if (targetMedian != 0) try {
+        final WraparoundTransform tr = new WraparoundTransform(dimension, 
wraparoundDimension, period, sourceMedian - targetMedian);
+        if (targetMedian == 0) {
+            return tr;
+        } else try {
             final double[] vector = new double[dimension];
             vector[wraparoundDimension] = targetMedian;
             final MathTransform denormalize = 
MathTransforms.translation(vector);
-            tr = MathTransforms.concatenate(denormalize.inverse(), tr, 
denormalize);
+            final MathTransform ct = 
MathTransforms.concatenate(denormalize.inverse(), tr, denormalize);
+            if (sourceMedian == 0) {
+                tr.inverse = tr;        // For preventing a stack overflow in 
`DomainDefinition.estimateOnInverse(…)`
+            }
+            return ct;
         } catch (NoninvertibleTransformException e) {
             throw new IllegalArgumentException(e);              // Should 
never happen actually.
         }
-        return tr;
     }
 
     /**

Reply via email to