Kouhei Sutou
null+****@clear*****
Tue Aug 28 10:10:27 JST 2018
Kouhei Sutou 2018-08-28 10:10:27 +0900 (Tue, 28 Aug 2018) Revision: a1c7cdbe328951cfbf126d6b1760c86c571b04f8 https://github.com/groonga/groonga/commit/a1c7cdbe328951cfbf126d6b1760c86c571b04f8 Message: vector_find: avoid to crash with unsupported modes Added files: test/command/suite/select/function/vector/vector_find/mode/unsupported_uvector_number.expected test/command/suite/select/function/vector/vector_find/mode/unsupported_uvector_number.test test/command/suite/select/function/vector/vector_find/mode/unsupported_uvector_record.expected test/command/suite/select/function/vector/vector_find/mode/unsupported_uvector_record.test test/command/suite/select/function/vector/vector_find/mode/unsupported_vector.expected Copied files: test/command/suite/select/function/vector/vector_find/mode/invalid.test (from test/command/suite/select/function/vector/vector_find/invalid_mode.test) Modified files: plugins/functions/vector.c Renamed files: test/command/suite/select/function/vector/vector_find/mode/invalid.expected (from test/command/suite/select/function/vector/vector_find/invalid_mode.expected) test/command/suite/select/function/vector/vector_find/mode/unsupported_vector.test (from test/command/suite/select/function/vector/vector_find/invalid_mode.test) Modified: plugins/functions/vector.c (+21 -0) =================================================================== --- plugins/functions/vector.c 2018-08-28 10:03:45 +0900 (1fe11ff03) +++ plugins/functions/vector.c 2018-08-28 10:10:27 +0900 (b4e25fb9c) @@ -385,6 +385,12 @@ func_vector_find_vector(grn_ctx *ctx, unsigned int n_elements = 0; exec = grn_operator_to_exec_func(mode); + if (!exec) { + GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT, + "vector_find(): unsupported mode: <%s>", + grn_operator_to_string(mode)); + return NULL; + } GRN_VOID_INIT(&element); n_elements = grn_vector_size(ctx, target); for (i = 0; i < n_elements; i++) { @@ -457,6 +463,12 @@ func_vector_find_uvector_number(grn_ctx *ctx, grn_obj element; exec = grn_operator_to_exec_func(mode); + if (!exec) { + GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT, + "vector_find(): unsupported mode: <%s>", + grn_operator_to_string(mode)); + return NULL; + } GRN_VALUE_FIX_SIZE_INIT(&element, 0, target->header.domain); for (i = 0; i < n_elements; i++) { GRN_BULK_REWIND(&element); @@ -498,6 +510,9 @@ func_vector_find_uvector_record(grn_ctx *ctx, size_t i, n_elements; if (mode != GRN_OP_EQUAL) { + GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT, + "vector_find(): unsupported mode: <%s>", + grn_operator_to_string(mode)); return NULL; } @@ -567,6 +582,12 @@ func_vector_find_pvector(grn_ctx *ctx, unsigned int n_elements = 0; exec = grn_operator_to_exec_func(mode); + if (!exec) { + GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT, + "vector_find(): unsupported mode: <%s>", + grn_operator_to_string(mode)); + return NULL; + } elements = (grn_obj **)GRN_BULK_HEAD(target); n_elements = sizeof(grn_id) / GRN_BULK_VSIZE(target); for (i = 0; i < n_elements; i++) { Renamed: test/command/suite/select/function/vector/vector_find/mode/invalid.expected (+0 -0) 100% =================================================================== Copied: test/command/suite/select/function/vector/vector_find/mode/invalid.test (+0 -0) 100% =================================================================== Added: test/command/suite/select/function/vector/vector_find/mode/unsupported_uvector_number.expected (+68 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/vector/vector_find/mode/unsupported_uvector_number.expected 2018-08-28 10:10:27 +0900 (d457fe964) @@ -0,0 +1,68 @@ +plugin_register functions/vector +[[0,0.0,0.0],true] +table_create Memos TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +column_create Memos numbers COLUMN_VECTOR UInt8 +[[0,0.0,0.0],true] +load --table Memos +[ +{"_key": "Positive", "numbers": [5, 4, 3, 2, 1]}, +{"_key": "Even", "numbers": [10, 8, 6, 4, 2]}, +{"_key": "Nothing"} +] +[[0,0.0,0.0],3] +select Memos --output_columns 'numbers, vector_find(numbers, 4, "@$")' +[ + [ + [ + -22, + 0.0, + 0.0 + ], + "vector_find(): unsupported mode: <suffix>" + ], + [ + [ + [ + 3 + ], + [ + [ + "numbers", + "UInt8" + ], + [ + "vector_find", + null + ] + ], + [ + [ + 5, + 4, + 3, + 2, + 1 + ], + "vector_find(): unsupported mode: <suffix>" + ], + [ + [ + 10, + 8, + 6, + 4, + 2 + ], + "vector_find(): unsupported mode: <suffix>" + ], + [ + [ + + ], + "vector_find(): unsupported mode: <suffix>" + ] + ] + ] +] +#|e| vector_find(): unsupported mode: <suffix> Added: test/command/suite/select/function/vector/vector_find/mode/unsupported_uvector_number.test (+14 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/vector/vector_find/mode/unsupported_uvector_number.test 2018-08-28 10:10:27 +0900 (e6a73d924) @@ -0,0 +1,14 @@ +plugin_register functions/vector + +table_create Memos TABLE_HASH_KEY ShortText +column_create Memos numbers COLUMN_VECTOR UInt8 + +load --table Memos +[ +{"_key": "Positive", "numbers": [5, 4, 3, 2, 1]}, +{"_key": "Even", "numbers": [10, 8, 6, 4, 2]}, +{"_key": "Nothing"} +] + +select Memos \ + --output_columns 'numbers, vector_find(numbers, 4, "@$")' Added: test/command/suite/select/function/vector/vector_find/mode/unsupported_uvector_record.expected (+66 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/vector/vector_find/mode/unsupported_uvector_record.expected 2018-08-28 10:10:27 +0900 (55a47c065) @@ -0,0 +1,66 @@ +plugin_register functions/vector +[[0,0.0,0.0],true] +table_create Tags TABLE_PAT_KEY ShortText +[[0,0.0,0.0],true] +table_create Memos TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +column_create Memos tags COLUMN_VECTOR Tags +[[0,0.0,0.0],true] +load --table Memos +[ +{"_key": "Groonga", "tags": ["Groonga", "Full text search"]}, +{"_key": "Rroonga", "tags": ["Groonga", "Full text search", "Ruby", "Library"]}, +{"_key": "Nothing"} +] +[[0,0.0,0.0],3] +select Memos --output_columns 'tags, vector_find(tags, "Full text search", "@")' +[ + [ + [ + -22, + 0.0, + 0.0 + ], + "vector_find(): unsupported mode: <match>" + ], + [ + [ + [ + 3 + ], + [ + [ + "tags", + "Tags" + ], + [ + "vector_find", + null + ] + ], + [ + [ + "Groonga", + "Full text search" + ], + "vector_find(): unsupported mode: <match>" + ], + [ + [ + "Groonga", + "Full text search", + "Ruby", + "Library" + ], + "vector_find(): unsupported mode: <match>" + ], + [ + [ + + ], + "vector_find(): unsupported mode: <match>" + ] + ] + ] +] +#|e| vector_find(): unsupported mode: <match> Added: test/command/suite/select/function/vector/vector_find/mode/unsupported_uvector_record.test (+16 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/vector/vector_find/mode/unsupported_uvector_record.test 2018-08-28 10:10:27 +0900 (a80cbcdea) @@ -0,0 +1,16 @@ +plugin_register functions/vector + +table_create Tags TABLE_PAT_KEY ShortText + +table_create Memos TABLE_HASH_KEY ShortText +column_create Memos tags COLUMN_VECTOR Tags + +load --table Memos +[ +{"_key": "Groonga", "tags": ["Groonga", "Full text search"]}, +{"_key": "Rroonga", "tags": ["Groonga", "Full text search", "Ruby", "Library"]}, +{"_key": "Nothing"} +] + +select Memos \ + --output_columns 'tags, vector_find(tags, "Full text search", "@")' Added: test/command/suite/select/function/vector/vector_find/mode/unsupported_vector.expected (+63 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/function/vector/vector_find/mode/unsupported_vector.expected 2018-08-28 10:10:27 +0900 (4fa038d41) @@ -0,0 +1,63 @@ +plugin_register functions/vector +[[0,0.0,0.0],true] +table_create Memos TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +column_create Memos tags COLUMN_VECTOR ShortText +[[0,0.0,0.0],true] +load --table Memos +[ +{"_key": "Groonga", "tags": ["Great", "Groonga"]}, +{"_key": "Rroonga", "tags": ["Full text search", "Groonga", "Ruby"]}, +{"_key": "Nothing"} +] +[[0,0.0,0.0],3] +select Memos --output_columns 'tags, vector_find(tags, "ga", "@$")' +[ + [ + [ + -22, + 0.0, + 0.0 + ], + "vector_find(): unsupported mode: <suffix>" + ], + [ + [ + [ + 3 + ], + [ + [ + "tags", + "ShortText" + ], + [ + "vector_find", + null + ] + ], + [ + [ + "Great", + "Groonga" + ], + "vector_find(): unsupported mode: <suffix>" + ], + [ + [ + "Full text search", + "Groonga", + "Ruby" + ], + "vector_find(): unsupported mode: <suffix>" + ], + [ + [ + + ], + "vector_find(): unsupported mode: <suffix>" + ] + ] + ] +] +#|e| vector_find(): unsupported mode: <suffix> Renamed: test/command/suite/select/function/vector/vector_find/mode/unsupported_vector.test (+1 -1) 83% =================================================================== --- test/command/suite/select/function/vector/vector_find/invalid_mode.test 2018-08-28 10:03:45 +0900 (89f37f236) +++ test/command/suite/select/function/vector/vector_find/mode/unsupported_vector.test 2018-08-28 10:10:27 +0900 (889f4a61c) @@ -11,4 +11,4 @@ load --table Memos ] select Memos \ - --output_columns 'tags, vector_find(tags, "Gr", "invalid")' + --output_columns 'tags, vector_find(tags, "ga", "@$")' -------------- next part -------------- HTML����������������������������... URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180828/59e6c7e4/attachment-0001.htm