Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
62183: geogen: disallow EMPTY in multi and geometry collections r=otan a=andyyang890

Allowing EMPTYs inside multi or geometry collections was
causing panics due to a GEOS bug. This patch explicitly
disallows such geometries from being generated.

Fixes cockroachdb#62141.

Release note: None

Co-authored-by: Andy Yang <[email protected]>
  • Loading branch information
craig[bot] and Andy Yang committed Mar 18, 2021
2 parents 7444c8a + 8f71602 commit d7a553b
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions pkg/geo/geogen/geogen.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,12 @@ func RandomMultiPoint(
// 10% chance to generate an empty multipoint (when num is 0).
num := rng.Intn(10)
for i := 0; i < num; i++ {
if err := ret.Push(RandomPoint(rng, randomBounds, srid, layout)); err != nil {
// TODO(#62184): permit EMPTY collection item once GEOS is patched
var point *geom.Point
for point == nil || point.Empty() {
point = RandomPoint(rng, randomBounds, srid, layout)
}
if err := ret.Push(point); err != nil {
panic(err)
}
}
Expand All @@ -224,7 +229,12 @@ func RandomMultiLineString(
// 10% chance to generate an empty multilinestring (when num is 0).
num := rng.Intn(10)
for i := 0; i < num; i++ {
if err := ret.Push(RandomLineString(rng, randomBounds, srid, layout)); err != nil {
// TODO(#62184): permit EMPTY collection item once GEOS is patched
var lineString *geom.LineString
for lineString == nil || lineString.Empty() {
lineString = RandomLineString(rng, randomBounds, srid, layout)
}
if err := ret.Push(lineString); err != nil {
panic(err)
}
}
Expand All @@ -240,7 +250,12 @@ func RandomMultiPolygon(
// 10% chance to generate an empty multipolygon (when num is 0).
num := rng.Intn(10)
for i := 0; i < num; i++ {
if err := ret.Push(RandomPolygon(rng, randomBounds, srid, layout)); err != nil {
// TODO(#62184): permit EMPTY collection item once GEOS is patched
var polygon *geom.Polygon
for polygon == nil || polygon.Empty() {
polygon = RandomPolygon(rng, randomBounds, srid, layout)
}
if err := ret.Push(polygon); err != nil {
panic(err)
}
}
Expand All @@ -265,6 +280,10 @@ func RandomGeometryCollection(
for needShape {
shape = RandomGeomT(rng, randomBounds, srid, layout)
_, needShape = shape.(*geom.GeometryCollection)
// TODO(#62184): permit EMPTY collection item once GEOS is patched
if shape.Empty() {
needShape = true
}
}
if err := ret.Push(shape); err != nil {
panic(err)
Expand Down

0 comments on commit d7a553b

Please sign in to comment.