Author: jbellis
Date: Thu Jan 21 15:46:41 2010
New Revision: 901748
URL: http://svn.apache.org/viewvc?rev=901748&view=rev
Log:
enforce already-present requirement that encoded key length not exceed 64K at
the thrift level. patch by jbellis
Modified:
incubator/cassandra/trunk/src/java/org/apache/cassandra/service/ThriftValidation.java
incubator/cassandra/trunk/test/system/test_server.py
Modified:
incubator/cassandra/trunk/src/java/org/apache/cassandra/service/ThriftValidation.java
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/service/ThriftValidation.java?rev=901748&r1=901747&r2=901748&view=diff
==============================================================================
---
incubator/cassandra/trunk/src/java/org/apache/cassandra/service/ThriftValidation.java
(original)
+++
incubator/cassandra/trunk/src/java/org/apache/cassandra/service/ThriftValidation.java
Thu Jan 21 15:46:41 2010
@@ -42,6 +42,21 @@
{
throw new InvalidRequestException("Key may not be empty");
}
+ // check that writeUTF will be able to handle it -- encoded length
must fit in 2 bytes
+ int strlen = key.length();
+ int utflen = 0;
+ for (int i = 0; i < strlen; i++)
+ {
+ int c = key.charAt(i);
+ if ((c >= 0x0001) && (c <= 0x007F))
+ utflen++;
+ else if (c > 0x07FF)
+ utflen += 3;
+ else
+ utflen += 2;
+ }
+ if (utflen > 65535)
+ throw new InvalidRequestException("Encoded key length of " +
utflen + " is longer than maximum of 65535");
}
private static void validateTable(String tablename) throws
KeyspaceNotDefinedException
Modified: incubator/cassandra/trunk/test/system/test_server.py
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/system/test_server.py?rev=901748&r1=901747&r2=901748&view=diff
==============================================================================
--- incubator/cassandra/trunk/test/system/test_server.py (original)
+++ incubator/cassandra/trunk/test/system/test_server.py Thu Jan 21 15:46:41
2010
@@ -493,6 +493,8 @@
def test_bad_calls(self):
# supercolumn in a non-super CF
_expect_exception(lambda: client.insert('Keyspace1', 'key1',
ColumnPath('Standard1', 'x', 'y'), 'value', 0, ConsistencyLevel.ONE),
InvalidRequestException)
+ # key too long
+ _expect_exception(lambda: client.get('Keyspace1', 'x' * 2**16,
ColumnPath('Standard1', column='c1'), ConsistencyLevel.ONE),
InvalidRequestException)
# empty key
_expect_exception(lambda: client.get('Keyspace1', '',
ColumnPath('Standard1', column='c1'), ConsistencyLevel.ONE),
InvalidRequestException)
cfmap = {'Super1': [ColumnOrSuperColumn(super_column=c) for c in
_SUPER_COLUMNS],