cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brandonwilli...@apache.org
Subject [10/14] git commit: Fix for IndexHelper.IndexFor OOB Exception
Date Fri, 07 Dec 2012 21:44:14 GMT
Fix for IndexHelper.IndexFor OOB Exception

Patch by tjake; reviewed by jbellis for CASSANDRA-5030


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/f91001a0
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/f91001a0
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/f91001a0

Branch: refs/heads/cassandra-1.2
Commit: f91001a085886a75f62c7eef019fd32bdc4c9fe1
Parents: 248d626
Author: Jake Luciani <jluciani@bluemountaincapital.com>
Authored: Fri Dec 7 14:47:52 2012 -0500
Committer: Jake Luciani <jluciani@bluemountaincapital.com>
Committed: Fri Dec 7 14:47:52 2012 -0500

----------------------------------------------------------------------
 CHANGES.txt                                        |    2 +-
 .../db/columniterator/SSTableNamesIterator.java    |    2 +-
 .../apache/cassandra/io/sstable/IndexHelper.java   |    4 ++
 .../cassandra/io/sstable/IndexHelperTest.java      |   33 ++++++++++-----
 4 files changed, 28 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/f91001a0/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index d3e04a7..9a41c87 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -8,7 +8,7 @@
  * Fix message when trying to alter a clustering key type (CASSANDRA-5012)
 Merged from 1.1
  * Improve schema propagation performance (CASSANDRA-5025)
-
+ * Fix for IndexHelper.IndexFor throws OOB Exception (CASSANDRA-5030)
 
 1.2-beta3
  * make consistency level configurable in cqlsh (CASSANDRA-4829)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f91001a0/src/java/org/apache/cassandra/db/columniterator/SSTableNamesIterator.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/columniterator/SSTableNamesIterator.java b/src/java/org/apache/cassandra/db/columniterator/SSTableNamesIterator.java
index 766c282..da4631d 100644
--- a/src/java/org/apache/cassandra/db/columniterator/SSTableNamesIterator.java
+++ b/src/java/org/apache/cassandra/db/columniterator/SSTableNamesIterator.java
@@ -234,7 +234,7 @@ public class SSTableNamesIterator extends SimpleAbstractColumnIterator
implement
         for (ByteBuffer name : filteredColumnNames)
         {
             int index = IndexHelper.indexFor(name, indexList, comparator, false, lastIndexIdx);
-            if (index == indexList.size())
+            if (index < 0 || index == indexList.size())
                 continue;
             IndexHelper.IndexInfo indexInfo = indexList.get(index);
             // Check the index block does contain the column names and that we haven't inserted
this block yet.

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f91001a0/src/java/org/apache/cassandra/io/sstable/IndexHelper.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/sstable/IndexHelper.java b/src/java/org/apache/cassandra/io/sstable/IndexHelper.java
index d01c45d..6a2e101 100644
--- a/src/java/org/apache/cassandra/io/sstable/IndexHelper.java
+++ b/src/java/org/apache/cassandra/io/sstable/IndexHelper.java
@@ -154,6 +154,10 @@ public class IndexHelper
     {
         if (name.remaining() == 0 && reversed)
             return indexList.size() - 1;
+
+        if (lastIndex >= indexList.size())
+            return -1;
+
         IndexInfo target = new IndexInfo(name, name, 0, 0);
         /*
         Take the example from the unit test, and say your index looks like this:

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f91001a0/test/unit/org/apache/cassandra/io/sstable/IndexHelperTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/io/sstable/IndexHelperTest.java b/test/unit/org/apache/cassandra/io/sstable/IndexHelperTest.java
index d5370d6..d96cab1 100644
--- a/test/unit/org/apache/cassandra/io/sstable/IndexHelperTest.java
+++ b/test/unit/org/apache/cassandra/io/sstable/IndexHelperTest.java
@@ -20,6 +20,9 @@ package org.apache.cassandra.io.sstable;
 
 import java.util.ArrayList;
 import java.util.List;
+
+import static junit.framework.Assert.*;
+
 import org.junit.Test;
 
 import org.apache.cassandra.db.marshal.AbstractType;
@@ -39,16 +42,24 @@ public class IndexHelperTest
 
         AbstractType comp = IntegerType.instance;
 
-        assert 0 == IndexHelper.indexFor(bytes(-1L), indexes, comp, false, -1);
-        assert 0 == IndexHelper.indexFor(bytes(5L), indexes, comp, false, -1);
-        assert 1 == IndexHelper.indexFor(bytes(12L), indexes, comp, false, -1);
-        assert 2 == IndexHelper.indexFor(bytes(17L), indexes, comp, false, -1);
-        assert 3 == IndexHelper.indexFor(bytes(100L), indexes, comp, false, -1);
-
-        assert -1 == IndexHelper.indexFor(bytes(-1L), indexes, comp, true, -1);
-        assert 0 == IndexHelper.indexFor(bytes(5L), indexes, comp, true, -1);
-        assert 1 == IndexHelper.indexFor(bytes(12L), indexes, comp, true, -1);
-        assert 1 == IndexHelper.indexFor(bytes(17L), indexes, comp, true, -1);
-        assert 2 == IndexHelper.indexFor(bytes(100L), indexes, comp, true, -1);
+        assertEquals(0, IndexHelper.indexFor(bytes(-1L), indexes, comp, false, -1));
+        assertEquals(0, IndexHelper.indexFor(bytes(5L), indexes, comp, false, -1));
+        assertEquals(1, IndexHelper.indexFor(bytes(12L), indexes, comp, false, -1));
+        assertEquals(2, IndexHelper.indexFor(bytes(17L), indexes, comp, false, -1));
+        assertEquals(3, IndexHelper.indexFor(bytes(100L), indexes, comp, false, -1));
+        assertEquals(1, IndexHelper.indexFor(bytes(100L), indexes, comp, false, 0));
+        assertEquals(2, IndexHelper.indexFor(bytes(100L), indexes, comp, false, 1));
+        assertEquals(3, IndexHelper.indexFor(bytes(100L), indexes, comp, false, 2));
+        assertEquals(-1, IndexHelper.indexFor(bytes(100L), indexes, comp, false, 3));
+
+        assertEquals(-1, IndexHelper.indexFor(bytes(-1L), indexes, comp, true, -1));
+        assertEquals(0, IndexHelper.indexFor(bytes(5L), indexes, comp, true, -1));
+        assertEquals(1, IndexHelper.indexFor(bytes(17L), indexes, comp, true, -1));
+        assertEquals(2, IndexHelper.indexFor(bytes(100L), indexes, comp, true, -1));
+        assertEquals(2, IndexHelper.indexFor(bytes(100L), indexes, comp, true, 0));
+        assertEquals(1, IndexHelper.indexFor(bytes(12L), indexes, comp, true, -1));
+        assertEquals(2, IndexHelper.indexFor(bytes(100L), indexes, comp, true, 1));
+        assertEquals(2, IndexHelper.indexFor(bytes(100L), indexes, comp, true, 2));
+        assertEquals(-1, IndexHelper.indexFor(bytes(100L), indexes, comp, true, 4));
     }
 }


Mime
View raw message