[Groonga-commit] groonga/groonga [master] Fix a crash bug of geo_in_circle()

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Mar 27 18:00:30 JST 2013


Kouhei Sutou	2013-03-27 18:00:30 +0900 (Wed, 27 Mar 2013)

  New Revision: 64e5138b8c94be60e65d171425c10f26f738db0a
  https://github.com/groonga/groonga/commit/64e5138b8c94be60e65d171425c10f26f738db0a

  Message:
    Fix a crash bug of geo_in_circle()
    
    If point column doesn't have index, geo_in_circle() crshes. This
    change adds indexed check.

  Added files:
    test/command/suite/select/filter/geo_in_circle/no_index.expected
    test/command/suite/select/filter/geo_in_circle/no_index.test
  Modified files:
    lib/geo.c

  Modified: lib/geo.c (+28 -16)
===================================================================
--- lib/geo.c    2013-03-26 15:05:11 +0900 (4d2df99)
+++ lib/geo.c    2013-03-27 18:00:30 +0900 (88def6c)
@@ -760,25 +760,37 @@ grn_selector_geo_in_circle(grn_ctx *ctx, grn_obj *table, grn_obj *index,
 {
   grn_geo_approximate_type type = GRN_GEO_APPROXIMATE_RECTANGLE;
 
-  switch (nargs) {
-  case 5 :
-    if (grn_geo_resolve_approximate_type(ctx, args[4], &type) != GRN_SUCCESS) {
-      break;
-    }
-    /* fallthru */
-  case 4 :
-    {
-      grn_obj *center_point, *distance;
-      center_point = args[2];
-      distance = args[3];
-      grn_geo_select_in_circle(ctx, index, center_point, distance, type, res, op);
-    }
-    break;
-  default :
+  if (!(nargs == 4 || nargs == 5)) {
     ERR(GRN_INVALID_ARGUMENT,
         "geo_in_circle(): requires 3 or 4 arguments but was <%d> arguments",
         nargs - 1);
-    break;
+    return ctx->rc;
+  }
+
+  if (!index) {
+    grn_obj *point_column;
+    char column_name[GRN_TABLE_MAX_KEY_SIZE];
+    int column_name_size;
+    point_column = args[1];
+    column_name_size = grn_obj_name(ctx, point_column,
+                                    column_name, GRN_TABLE_MAX_KEY_SIZE);
+    ERR(GRN_INVALID_ARGUMENT,
+        "geo_in_circle(): index for <%.*s> is missing",
+        column_name_size, column_name);
+    return ctx->rc;
+  }
+
+  if (nargs == 5) {
+    if (grn_geo_resolve_approximate_type(ctx, args[4], &type) != GRN_SUCCESS) {
+      return ctx->rc;
+    }
+  }
+
+  {
+    grn_obj *center_point, *distance;
+    center_point = args[2];
+    distance = args[3];
+    grn_geo_select_in_circle(ctx, index, center_point, distance, type, res, op);
   }
 
   return ctx->rc;

  Added: test/command/suite/select/filter/geo_in_circle/no_index.expected (+5 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/geo_in_circle/no_index.expected    2013-03-27 18:00:30 +0900 (509bfb1)
@@ -0,0 +1,5 @@
+column_remove Locations shop
+[[0,0.0,0.0],true]
+select Shops --sortby '+_score, +name'   --output_columns 'name, _score, location'   --filter 'geo_in_circle(location, "128429532x503148672", 3000)'   --scorer '_score = geo_distance(location, "128429532x503148672") * 1000 * 1000'
+[[[-22,0.0,0.0],"geo_in_circle(): index for <Shops.location> is missing"],[]]
+#|e| geo_in_circle(): index for <Shops.location> is missing

  Added: test/command/suite/select/filter/geo_in_circle/no_index.test (+8 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/geo_in_circle/no_index.test    2013-03-27 18:00:30 +0900 (a9a23aa)
@@ -0,0 +1,8 @@
+#@include fixture/geo/taiyaki/init.grn
+
+column_remove Locations shop
+
+select Shops --sortby '+_score, +name' \
+  --output_columns 'name, _score, location' \
+  --filter 'geo_in_circle(location, "128429532x503148672", 3000)' \
+  --scorer '_score = geo_distance(location, "128429532x503148672") * 1000 * 1000'
-------------- next part --------------
HTML����������������������������...
다운로드 



More information about the Groonga-commit mailing list
Back to archive index