cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject git commit: Don't silently prepend '0' during hex-to-bytes conversion
Date Fri, 10 Feb 2012 19:14:34 GMT
Updated Branches:
  refs/heads/cassandra-1.1 4e6a4c016 -> 3eefbac13


Don't silently prepend '0' during hex-to-bytes conversion

patch by slebresne; reviewed by jbellis for CASSANDRA-2851


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

Branch: refs/heads/cassandra-1.1
Commit: 3eefbac133c838db46faa6a91ba1f114192557ae
Parents: 4e6a4c0
Author: Sylvain Lebresne <sylvain@datastax.com>
Authored: Fri Feb 10 20:12:55 2012 +0100
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Fri Feb 10 20:12:55 2012 +0100

----------------------------------------------------------------------
 CHANGES.txt                                        |    1 +
 .../dht/AbstractByteOrderedPartitioner.java        |    4 ++++
 src/java/org/apache/cassandra/utils/Hex.java       |    3 ++-
 test/unit/org/apache/cassandra/cli/CliTest.java    |    4 ++--
 test/unit/org/apache/cassandra/utils/HexTest.java  |    8 ++++----
 5 files changed, 13 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/3eefbac1/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 63323e4..5d9eaf9 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -70,6 +70,7 @@
  * fix system tests (CASSANDRA-3827)
  * CQL support for altering key_validation_class in ALTER TABLE (CASSANDRA-3781)
  * turn compression on by default (CASSANDRA-3871)
+ * make hexToBytes refuse invalid input (CASSANDRA-2851)
 
 
 1.0.8

http://git-wip-us.apache.org/repos/asf/cassandra/blob/3eefbac1/src/java/org/apache/cassandra/dht/AbstractByteOrderedPartitioner.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/dht/AbstractByteOrderedPartitioner.java b/src/java/org/apache/cassandra/dht/AbstractByteOrderedPartitioner.java
index 3f085e9..23c0123 100644
--- a/src/java/org/apache/cassandra/dht/AbstractByteOrderedPartitioner.java
+++ b/src/java/org/apache/cassandra/dht/AbstractByteOrderedPartitioner.java
@@ -150,6 +150,8 @@ public abstract class AbstractByteOrderedPartitioner extends AbstractPartitioner
         {
             try
             {
+                if (token.length() % 2 == 1)
+                    token = "0" + token;
                 Hex.hexToBytes(token);
             }
             catch (NumberFormatException e)
@@ -160,6 +162,8 @@ public abstract class AbstractByteOrderedPartitioner extends AbstractPartitioner
 
         public Token<byte[]> fromString(String string)
         {
+            if (string.length() % 2 == 1)
+                string = "0" + string;
             return new BytesToken(Hex.hexToBytes(string));
         }
     };

http://git-wip-us.apache.org/repos/asf/cassandra/blob/3eefbac1/src/java/org/apache/cassandra/utils/Hex.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/utils/Hex.java b/src/java/org/apache/cassandra/utils/Hex.java
index 757099e..7e61d9a 100644
--- a/src/java/org/apache/cassandra/utils/Hex.java
+++ b/src/java/org/apache/cassandra/utils/Hex.java
@@ -49,7 +49,8 @@ public class Hex
     public static byte[] hexToBytes(String str)
     {
         if (str.length() % 2 == 1)
-            str = "0" + str;
+            throw new NumberFormatException("An hex string representing bytes must have an
even length");
+
         byte[] bytes = new byte[str.length() / 2];
         for (int i = 0; i < bytes.length; i++)
         {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/3eefbac1/test/unit/org/apache/cassandra/cli/CliTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cli/CliTest.java b/test/unit/org/apache/cassandra/cli/CliTest.java
index 5232565..db93aed 100644
--- a/test/unit/org/apache/cassandra/cli/CliTest.java
+++ b/test/unit/org/apache/cassandra/cli/CliTest.java
@@ -163,8 +163,8 @@ public class CliTest extends CleanupHelper
         "create column family myCF with column_type='Super' and comparator='UTF8Type' AND
subcomparator='UTF8Type' AND default_validation_class=AsciiType;",
         "assume myCF keys as utf8;",
         "create column family Countries with comparator=UTF8Type and column_metadata=[ {column_name:
name, validation_class: UTF8Type} ];",
-        "set Countries[1][name] = USA;",
-        "get Countries[1][name];",
+        "set Countries[11][name] = USA;",
+        "get Countries[11][name];",
         "update column family Countries with compaction_strategy = 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy';",
         "create column family Cities with compaction_strategy = 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy'
and compaction_strategy_options = {min_sstable_size:1024};",
         "set myCF['key']['scName']['firstname'] = 'John';",

http://git-wip-us.apache.org/repos/asf/cassandra/blob/3eefbac1/test/unit/org/apache/cassandra/utils/HexTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/utils/HexTest.java b/test/unit/org/apache/cassandra/utils/HexTest.java
index 34a8b30..ece4be5 100644
--- a/test/unit/org/apache/cassandra/utils/HexTest.java
+++ b/test/unit/org/apache/cassandra/utils/HexTest.java
@@ -42,11 +42,11 @@ public class HexTest
     {
         String[] values = new String[]
         {
-            "0",
+            "00",
             "10",
-            "100",
-            "101",
-            "f",
+            "0100",
+            "0101",
+            "0f",
             "ff"
         };
         byte[][] expected = new byte[][]


Mime
View raw message