[Groonga-commit] groonga/groonga [master] Fix a crash bug that geo_distance() sort by index

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Feb 15 23:34:24 JST 2013


Kouhei Sutou	2013-02-15 23:34:24 +0900 (Fri, 15 Feb 2013)

  New Revision: 0968491d39d7dcb10b9ef8347c71514de01e775b
  https://github.com/groonga/groonga/commit/0968491d39d7dcb10b9ef8347c71514de01e775b

  Log:
    Fix a crash bug that geo_distance() sort by index
    
    If there is any not indexed GeoPoint entry, geo_distance() sort by
    index may cause a crash. Because it touches uninitialized area.
    
    Not initialized GeoPoint value or initialized by 0x0 value are not
    indexed. If they aren't ignored, groonga may be crashed.

  Added files:
    test/command/suite/select/sort/geo/distance/not_indexed.expected
    test/command/suite/select/sort/geo/distance/not_indexed.test
  Modified files:
    lib/geo.c

  Modified: lib/geo.c (+5 -0)
===================================================================
--- lib/geo.c    2013-02-15 12:56:29 +0900 (78571b6)
+++ lib/geo.c    2013-02-15 23:34:24 +0900 (942ae39)
@@ -638,6 +638,8 @@ grn_geo_table_sort(grn_ctx *ctx, grn_obj *table, int offset, int limit,
           grn_geo_point *base_point;
           geo_entry *ep;
 
+          memset(entries, 0, sizeof(geo_entry) * (e + 1));
+
           base_point = (grn_geo_point *)GRN_BULK_HEAD(arg);
           n = grn_geo_table_sort_detect_far_point(ctx, table, index, pat,
                                                   entries, pc, e, accessorp,
@@ -650,6 +652,9 @@ grn_geo_table_sort(grn_ctx *ctx, grn_obj *table, int offset, int limit,
                                                    base_point, d_far, diff_bit);
           }
           for (i = 0, ep = entries + offset; i < limit && ep < entries + n; i++, ep++) {
+            if (ep->id == GRN_ID_NIL) {
+              break;
+            }
             if (!grn_array_add(ctx, (grn_array *)result, (void **)&v)) { break; }
             *v = ep->id;
           }

  Added: test/command/suite/select/sort/geo/distance/not_indexed.expected (+50 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/sort/geo/distance/not_indexed.expected    2013-02-15 23:34:24 +0900 (c9dcbe5)
@@ -0,0 +1,50 @@
+table_create  Locations      TABLE_PAT_KEY  WGS84GeoPoint
+[[0,0.0,0.0],true]
+table_create  Shops          TABLE_NO_KEY
+[[0,0.0,0.0],true]
+column_create Shops name     COLUMN_SCALAR  ShortText
+[[0,0.0,0.0],true]
+column_create Shops location COLUMN_SCALAR  WGS84GeoPoint
+[[0,0.0,0.0],true]
+column_create Locations shop COLUMN_INDEX Shops location
+[[0,0.0,0.0],true]
+load --table Shops
+[
+{"name":"根津のたいやき",  "location":"128592911x503145263"},
+{"name":"たい焼 カタオカ", "location":null}
+]
+[[0,0.0,0.0],2]
+select Shops   --sortby 'geo_distance(location, "35.67487x139.76352")'   --output_columns '_id, name, location'
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        2
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "name",
+          "ShortText"
+        ],
+        [
+          "location",
+          "WGS84GeoPoint"
+        ]
+      ],
+      [
+        1,
+        "根津のたいやき",
+        "128592911x503145263"
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/sort/geo/distance/not_indexed.test (+18 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/sort/geo/distance/not_indexed.test    2013-02-15 23:34:24 +0900 (336c187)
@@ -0,0 +1,18 @@
+table_create  Locations      TABLE_PAT_KEY  WGS84GeoPoint
+
+table_create  Shops          TABLE_NO_KEY
+column_create Shops name     COLUMN_SCALAR  ShortText
+column_create Shops location COLUMN_SCALAR  WGS84GeoPoint
+
+column_create Locations shop COLUMN_INDEX Shops location
+
+load --table Shops
+[
+{"name":"根津のたいやき",  "location":"128592911x503145263"},
+{"name":"たい焼 カタオカ", "location":null}
+]
+
+select Shops \
+  --sortby 'geo_distance(location, "35.67487x139.76352")' \
+  --output_columns '_id, name, location'
+
-------------- next part --------------
HTML����������������������������...
Download 



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