Skip to content

Commit

Permalink
Fix core dump when cast returns a non Geos object (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
BuonOmo committed Jun 27, 2021
1 parent 42e48d0 commit 6f24106
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
11 changes: 5 additions & 6 deletions ext/geos_c_impl/factory.c
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,6 @@ VALUE rgeo_wrap_geos_geometry_clone(VALUE factory, const GEOSGeometry* geom, VAL
const GEOSGeometry* rgeo_convert_to_geos_geometry(VALUE factory, VALUE obj, VALUE type)
{
VALUE object;
const GEOSGeometry* geom;
RGeo_Globals* globals;

if (NIL_P(type) && TYPE(obj) == T_DATA && RDATA(obj)->dfree == (RUBY_DATA_FUNC)destroy_geometry_func && RGEO_GEOMETRY_DATA_PTR(obj)->factory == factory) {
Expand All @@ -783,11 +782,11 @@ const GEOSGeometry* rgeo_convert_to_geos_geometry(VALUE factory, VALUE obj, VALU
globals = RGEO_FACTORY_DATA_PTR(factory)->globals;
object = rb_funcall(globals->feature_module, globals->id_cast, 3, obj, factory, type);
}
geom = NULL;
if (!NIL_P(object)) {
geom = RGEO_GEOMETRY_DATA_PTR(object)->geom;
}
return geom;
if (NIL_P(object))
return NULL;

Check_Type(object, T_DATA);
return RGEO_GEOMETRY_DATA_PTR(object)->geom;
}


Expand Down
9 changes: 8 additions & 1 deletion test/geos_capi/misc_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#
# -----------------------------------------------------------------------------

require "test_helper"
require "ostruct"
require_relative "../test_helper"

class GeosMiscTest < Minitest::Test # :nodoc:
def setup
Expand Down Expand Up @@ -137,6 +138,12 @@ def test_unary_union_mixed_collection
assert_equal(nil, geom)
end
end

def test_casting_dumb_objects
assert_raises(TypeError) do
RGeo::Geos.factory.point(1, 1).contains?(OpenStruct.new(factory: RGeo::Geos.factory))
end
end
end if RGeo::Geos.capi_supported?

unless RGeo::Geos.capi_supported?
Expand Down

0 comments on commit 6f24106

Please sign in to comment.