Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-13666

Near queries with out-of-bounds points in legacy format can lead to crash

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.6.1, 2.7.0
    • Affects Version/s: 2.6.0
    • Component/s: Geo
    • ALL
    • Hide
      from bson import SON
      from pymongo import Connection
      from pymongo.errors import OperationFailure, AutoReconnect
      
      db = Connection()["test"]
      db.users.insert({"loc": [1, 2]})
      db.users.insert({"loc": [2, 3]})
      db.users.insert({"loc": [3, 4]})
      db.users.ensure_index([("loc", "2dsphere")])
      
      #right way just raise error
      try:
          db.command(SON([('geoNear', 'users'), ('near', {'type': 'Point', 'coordinates': [100, 500]}), ('spherical', True),
                          ('minDistance', 0), ('query', {"loc": {"$exists": True}}), ('num', 48)]))
      except OperationFailure as e:
          print e
      """>>> command SON([('geoNear', 'users'), ('near', {'type': 'Point', 'coordinates': [100, 500]}), ('spherical', True),
       ('minDistance', 0), ('query', {'push': {'$gt': 0}}), ('num', 48)]) failed: exception: 'near' field must be point"""
      
      
      
      #wrong way but result is ok
      print db.command(SON([('geoNear', 'users'), ('near', [120.466, 31.2051]), ('spherical', True), ('minDistance', 0),
                            ('query', {"loc": {"$exists": True}}), ('num', 48)]))["ok"]
      
      """>>> 1.0"""
      
      
      #wrong way crash the server
      try:
          db.command(SON([('geoNear', 'users'), ('near', [1210.466, 31.2051]), ('spherical', True), ('minDistance', 0),
                          ('query', {"loc": {"$exists": True}}), ('num', 48)]))
      except AutoReconnect as e:
          print e
      
      """>>>connection closed"""
      
      Show
      from bson import SON from pymongo import Connection from pymongo.errors import OperationFailure, AutoReconnect db = Connection()[ "test" ] db.users.insert({ "loc" : [1, 2]}) db.users.insert({ "loc" : [2, 3]}) db.users.insert({ "loc" : [3, 4]}) db.users.ensure_index([( "loc" , "2dsphere" )]) #right way just raise error try : db.command(SON([( 'geoNear' , 'users' ), ( 'near' , { ' type ' : 'Point' , 'coordinates' : [100, 500]}), ( 'spherical' , True ), ( 'minDistance' , 0), ( 'query' , { "loc" : { "$exists" : True }}), ( 'num' , 48)])) except OperationFailure as e: print e """>>> command SON([( 'geoNear' , 'users' ), ( 'near' , { ' type ' : 'Point' , 'coordinates' : [100, 500]}), ( 'spherical' , True ), ( 'minDistance' , 0), ( 'query' , { 'push' : { '$gt' : 0}}), ( 'num' , 48)]) failed: exception: 'near' field must be point""" #wrong way but result is ok print db.command(SON([( 'geoNear' , 'users' ), ( 'near' , [120.466, 31.2051]), ( 'spherical' , True ), ( 'minDistance' , 0), ( 'query' , { "loc" : { "$exists" : True }}), ( 'num' , 48)]))[ "ok" ] """>>> 1.0" "" #wrong way crash the server try : db.command(SON([( 'geoNear' , 'users' ), ( 'near' , [1210.466, 31.2051]), ( 'spherical' , True ), ( 'minDistance' , 0), ( 'query' , { "loc" : { "$exists" : True }}), ( 'num' , 48)])) except AutoReconnect as e: print e """>>>connection closed" ""

      Draft for release summary box:

      Issue Status as of April 22, 2014

      ISSUE SUMMARY
      Query points provided in the legacy coordinate pair format using 2dsphere indexes are not correctly checked for whether they are in bounds. This affects both the geoNear command using the spherical option and the $nearSphere operator. Such out of bounds coordinates can crash the server.

      USER IMPACT
      A primary crash will lead to a fail-over in a replica set. If the queries continue to be sent to current primary (and cause a crash), this will affect quorum and potentially render the replica set inoperable.

      WORKAROUNDS
      Removing the spherical option for the query avoids the crash but will assume a flat surface instead of a spherical one. For small regions, the difference may be acceptable as a workaround.

      RESOLUTION
      The query now correctly checks for the bounds and aborts with an error, instead of crashing the server.

      AFFECTED VERSIONS
      Version 2.6.0 is affected by this bug.

      PATCHES
      The patch is included in the 2.6.1 production release.

      Original description

      use pymongo 2.7 client, when I runCommand query geoNear, the server crash.
      I know that maybe the issue of the pymongo client, but the server crash when the coordinates is wrong.

            Assignee:
            hari.khalsa@10gen.com hari.khalsa@10gen.com
            Reporter:
            nelson nelson_guo
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: