sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 01/02: Fix an `ArrayIndexOutOfBoundsException` occurring during sample value conversions because `lastUsed` unexpectedly became negative.
Date Thu, 08 Jul 2021 12:23:06 GMT
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

commit 710bd1a32ecc5c5fd1662cad03cb5c027f251eb5
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Thu Jul 8 14:19:07 2021 +0200

    Fix an `ArrayIndexOutOfBoundsException` occurring during sample value conversions because
`lastUsed` unexpectedly became negative.
---
 .../src/main/java/org/apache/sis/coverage/CategoryList.java        | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/CategoryList.java b/core/sis-feature/src/main/java/org/apache/sis/coverage/CategoryList.java
index d395e2c..430d214 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/CategoryList.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/CategoryList.java
@@ -550,7 +550,7 @@ final class CategoryList extends AbstractList<Category> implements
MathTransform
          */
         int index = lastUsed;
         double value = Double.NaN;
-main:   for (int peekOff = srcOff; /* numPts >= 0 */; peekOff += direction) {
+        for (int peekOff = srcOff; /* numPts >= 0 */; peekOff += direction) {
             final double minimum = minimums[index];
             final double limit = (index+1 < minimums.length) ? minimums[index+1] : Double.NaN;
             final long   rawBits = doubleToRawLongBits(minimum);
@@ -629,7 +629,10 @@ main:   for (int peekOff = srcOff; /* numPts >= 0 */; peekOff += direction)
{
             if (numPts < 0) break;
             while ((index = binarySearch(minimums, value)) < 0) {
                 dstPts[peekOff + srcToDst] = unmappedValue(value);
-                if (--numPts < 0) break main;
+                if (--numPts < 0) {
+                    // Skip also the assignment to `lastUsed` because `index` is invalid.
+                    return;
+                }
                 value = srcPts[peekOff += direction];
             }
             srcOff = peekOff;

Mime
View raw message