telefonicaid / fiware-orion

Context Broker and CEF building block for context data management, providing NGSI interfaces.
https://github.com/telefonicaid/fiware-orion/blob/master/doc/manuals/orion-api.md
GNU Affero General Public License v3.0
211 stars 265 forks source link

context broker crashes with invalid geoquery #690

Closed fgalan closed 9 years ago

fgalan commented 9 years ago

Reported by @PabloCGarcia (see https://github.com/telefonicaid/fiware-orion-pep/issues/97):

When we create a syntactically correct query but that is semantically incorrect, the broker crashes. We created the following query that combines a geo restriction of kind polygon and, in the same query, a restriction of kind circle, then the broker crashes.

The query is:

    jsonPoligono = '"restriction": {"scopes": [{ "type" : "FIWARE::Location","value" : {"polygon": {'+\
                   '"vertices": [' +\
                   '{"latitude": "-33.603458","longitude": "-70.652788"},' +\
                   '{"latitude": "-33.604231","longitude": "-70.646032"},' +\
                   '{"latitude": "-33.606123","longitude": "-70.646781"},' +\
                   '{"latitude": "-33.606123","longitude": "-70.646781"}' +\
                   ']}}},'
    jsonCirculo = '"{ "type" : "FIWARE::Location","value" : {"circle": {'+\
                  '"centerLatitude": "-33.602391",'+\
                  '"centerLongitude": "-70.661781",'+\
                  '"radius": "200"'+\
                  '}}}]}'
jsonX='{ "entities": [{"type": "","isPattern": "true","id": ".*"}],' + jsonPoligono + jsonCirculo+ '}'

resp = get_post_results("/v1/queryContext", jsonX)
for x in resp.iteritems():
    print "Elemento:", x[0]
    print "Atributos:"
    for y in x[1]:
        print "    Name:", y["name"], "Type:", y["type"], "Value:", y["value"]
fgalan commented 9 years ago

Some logs found at CB when this bug arises, just printed before the crash, that could be useful:

Sample 1:

INFO@19:24:49  MongoGlobal.cpp[1078]: Database Operation Successful ({ query: { $or: [ { _id.id: /.*/, _id.type: ".*" } ], _id.servicePath: { $in: [ /^/.*/, null ] }, location.coords: { $geoWithin: { $geometry: { type: "Polygon", coordinates: [ [ [ -70.652788, -33.603458 ], [ -70.64603200000001, -33.604231 ], [ -70.65379, -33.606123 ], [ -70.646781, -33.607108 ], [ -70.652788, -33.603458 ] ] ] } } } }, orderby: { creDate: 1 } })

Sample 2:

INFO@19:30:52  MongoGlobal.cpp[1078]: Database Operation Successful ({ query: { $or: [ { _id.id: /.*/, _id.type: "TypeC" } ], _id.servicePath: { $in: [ /^/.*/, null ] }, location.coords: { $geoWithin: { $geometry: { type: "Polygon", coordinates: [ [ [ -70.652788, -33.603458 ], [ -70.64603200000001, -33.604231 ], [ -70.65379, -33.606123 ], [ -70.646781, -33.607108 ], [ -70.652788, -33.603458 ] ] ] } } } }, orderby: { creDate: 1 } })
fgalan commented 9 years ago

Fixed in PR #698