Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"ArithmeticException[/ by zero]" when parsing a "polygon" "geo_shape" query with one pair of coordinates #8433

Closed
astefan opened this issue Nov 11, 2014 · 0 comments

Comments

Projects
None yet
2 participants
@astefan
Copy link
Contributor

commented Nov 11, 2014

For a query like this one:

{
  "query": {
    "geo_shape": {
      "location": {
        "shape": {
          "type": "polygon",
          "coordinates": [[["4.901238","52.36936"]]]
        }
      }
    }
  }
}

An "ArithmeticException: / by zero" is returned enclosed in a SearchParseException:

Caused by: java.lang.ArithmeticException: / by zero
    at org.elasticsearch.common.geo.builders.ShapeBuilder$Edge.ring(ShapeBuilder.java:460)
    at org.elasticsearch.common.geo.builders.BasePolygonBuilder.createEdges(BasePolygonBuilder.java:442)
    at org.elasticsearch.common.geo.builders.BasePolygonBuilder.coordinates(BasePolygonBuilder.java:129)
    at org.elasticsearch.common.geo.builders.BasePolygonBuilder.buildGeometry(BasePolygonBuilder.java:170)
    at org.elasticsearch.common.geo.builders.BasePolygonBuilder.build(BasePolygonBuilder.java:146)
    at org.elasticsearch.index.query.GeoShapeQueryParser.getArgs(GeoShapeQueryParser.java:173)
    at org.elasticsearch.index.query.GeoShapeQueryParser.parse(GeoShapeQueryParser.java:155)
    at org.elasticsearch.index.query.QueryParseContext.parseInnerQuery(QueryParseContext.java:252)
    at org.elasticsearch.index.query.IndexQueryParserService.innerParse(IndexQueryParserService.java:382)
    at org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:281)
    at org.elasticsearch.index.query.IndexQueryParserService.parse(IndexQueryParserService.java:276)
    at org.elasticsearch.search.query.QueryParseElement.parse(QueryParseElement.java:33)
    at org.elasticsearch.search.SearchService.parseSource(SearchService.java:665)

If I increase the number of coordinates for the polygon in the query to two, a more acceptable and meaningful exception is being thrown: "IllegalArgumentException[Invalid number of points in LinearRing (found 2 - must be 0 or >= 4)]". Probably, the same exception should be thrown and returned in case of just one set of coordinates.

nknize added a commit to nknize/elasticsearch that referenced this issue Nov 13, 2014

[GEO] Fix for ArithmeticException[/ by zero] when parsing a "polygon"…
… with one pair of coordinates

While this commit is primariy a fix for issue/8433 it adds more rigor to ShapeBuilder for parsing against the GeoJSON specification. Specifically, this adds LinearRing and LineString validity checks as defined in http://geojson.org/geojson-spec.html to ensure valid polygons are specified. The benefit of this fix is to provide a gate check at parse time to avoid any further processing if an invalid GeoJSON is provided.  More parse checks like these will be necessary going forward to ensure full compliance with the GeoJSON specification.

Closes elastic#8433

@nknize nknize self-assigned this Nov 17, 2014

@nknize nknize closed this in #8475 Nov 19, 2014

nknize added a commit that referenced this issue Nov 19, 2014

nknize added a commit that referenced this issue Nov 19, 2014

nknize added a commit that referenced this issue Nov 19, 2014

nknize added a commit that referenced this issue Nov 24, 2014

[GEO] Fix for ArithmeticException[/ by zero] when parsing a "polygon"…
… with one pair of coordinates

While this commit is primariy a fix for issue/8433 it adds more rigor to ShapeBuilder for parsing against the GeoJSON specification. Specifically, this adds LinearRing and LineString validity checks as defined in http://geojson.org/geojson-spec.html to ensure valid polygons are specified. The benefit of this fix is to provide a gate check at parse time to avoid any further processing if an invalid GeoJSON is provided.  More parse checks like these will be necessary going forward to ensure full compliance with the GeoJSON specification.

Closes #8433

mute pushed a commit to mute/elasticsearch that referenced this issue Jul 29, 2015

mute pushed a commit to mute/elasticsearch that referenced this issue Jul 29, 2015

[GEO] Fix for ArithmeticException[/ by zero] when parsing a "polygon"…
… with one pair of coordinates

While this commit is primariy a fix for issue/8433 it adds more rigor to ShapeBuilder for parsing against the GeoJSON specification. Specifically, this adds LinearRing and LineString validity checks as defined in http://geojson.org/geojson-spec.html to ensure valid polygons are specified. The benefit of this fix is to provide a gate check at parse time to avoid any further processing if an invalid GeoJSON is provided.  More parse checks like these will be necessary going forward to ensure full compliance with the GeoJSON specification.

Closes elastic#8433
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.