null+****@clear*****
null+****@clear*****
2011年 12月 19日 (月) 13:49:43 JST
Kouhei Sutou 2011-12-19 04:49:43 +0000 (Mon, 19 Dec 2011)
New Revision: d50b0e2f170372f0244193a3f70ae2524f856423
Log:
[shcema][table-create] check max key size.
refs #915
refs #1210
Modified files:
lib/db.c
test/unit/http/test-http-schema.rb
Modified: lib/db.c (+6 -0)
===================================================================
--- lib/db.c 2011-12-19 04:33:25 +0000 (f7a6306)
+++ lib/db.c 2011-12-19 04:49:43 +0000 (7a7d399)
@@ -710,6 +710,12 @@ grn_table_create(grn_ctx *ctx, const char *name, unsigned name_size,
grn_db_obj *t = (grn_db_obj *)key_type;
flags |= t->header.flags;
key_size = GRN_TYPE_SIZE(t);
+ if (key_size > GRN_TABLE_MAX_KEY_SIZE) {
+ ERR(GRN_INVALID_ARGUMENT,
+ "[table][create] key size too big: <%.*s> (%d) (max:%d)",
+ name_size, name, key_size, GRN_TABLE_MAX_KEY_SIZE);
+ GRN_API_RETURN(NULL);
+ }
}
break;
case GRN_TABLE_HASH_KEY :
Modified: test/unit/http/test-http-schema.rb (+10 -6)
===================================================================
--- test/unit/http/test-http-schema.rb 2011-12-19 04:33:25 +0000 (f506698)
+++ test/unit/http/test-http-schema.rb 2011-12-19 04:49:43 +0000 (3e66a99)
@@ -319,12 +319,14 @@ class HTTPSchemaTest < Test::Unit::TestCase
"null"]])
end
- def test_long_size_key
+ def test_big_size_key
response = get(command_path(:table_create,
:name => "users",
:key_type => "Text"))
- assert_error_response(Result::UNKNOWN_ERROR,
- "should implement error case",
+ assert_error_response(Result::INVALID_ARGUMENT,
+ "[table][create] " +
+ "key size too big: " +
+ "<users> (65536) (max:4096)",
response,
:content_type => "application/json")
@@ -443,13 +445,15 @@ class HTTPSchemaTest < Test::Unit::TestCase
"null"]])
end
- def test_long_size_key
+ def test_big_size_key
response = get(command_path(:table_create,
:name => "users",
:flags => Table::PAT_KEY,
:key_type => "Text"))
- assert_error_response(Result::UNKNOWN_ERROR,
- "should implement error case",
+ assert_error_response(Result::INVALID_ARGUMENT,
+ "[table][create] " +
+ "key size too big: " +
+ "<users> (65536) (max:4096)",
response,
:content_type => "application/json")