Opened 3 years ago

Closed 3 years ago

#4792 closed defect (wontfix)

ST_Transform crashes server (windows)

Reported by: robe Owned by: pramsey
Priority: high Milestone: PostGIS 3.1.0
Component: postgis Version: 3.0.x
Keywords: Cc:

Description

This might be just a windows or my misconfigured PROJ.

I pulled this example from pramsey's blog

SELECT ST_Astext(
         ST_Transform(
           ST_SetSRID(geometry('POINT(-100 40 100)'),7406), 
           5500));
		   

http://blog.cleverelephant.ca/2019/02/proj4-postgis.html

On PostGIS 3.0 with Proj 5.2 (POSTGIS="3.0.2 3.0.2" [EXTENSION] PGSQL="120" GEOS="3.8.1-CAPI-1.13.3" SFCGAL="1.3.8" PROJ="Rel. 5.2.0, September 15th, 2018" LIBXML="2.9.9" LIBJSON="0.12" LIBPROTOBUF="1.2.1" WAGYU="0.4.3 (Internal)") , doesn't work at all which is expected:

NOTICE:  PostGIS was unable to transform the point because either no grid shift files were found, or the point does not lie within the range for which the grid shift is defined. Refer to the ST_Transform() section of the PostGIS manual for details on how to configure PostGIS to alter this behaviour.

ERROR:  transform: couldn't project point (-100 40 100): failed to load datum shift file (-38)
SQL state: XX000

But on PostGIS 3.1.0 ( PostgreSQL 13.1, compiled by Visual C++ build 1914, 64-bit POSTGIS="3.1.0dev 3.1.0alpha2-157-gdfeaaac70" [EXTENSION] PGSQL="130" GEOS="3.9.0-CAPI-1.14.0" SFCGAL="1.3.8" PROJ="6.3.2" GDAL="GDAL 3.2.0, released 2020/10/26 GDAL_DATA not found" LIBXML="2.9.9" LIBJSON="0.12" LIBPROTOBUF="1.2.1" WAGYU="0.5.0 (Internal)" TOPOLOGY RASTER)

It just crashes.

I'll do a gdb check next to see where it is crashing.

Change History (7)

comment:1 by robe, 3 years ago

Priority: mediumhigh

Okay the good news is after I put in the PROJ_LIB env variable and restarted the service.

I get this:

POSTGIS="3.1.0dev 3.1.0alpha2-157-gdfeaaac70" [EXTENSION] PGSQL="130" GEOS="3.9.0-CAPI-1.14.0" SFCGAL="1.3.8" PROJ="6.3.2" GDAL="GDAL 3.2.0, released 2020/10/26" LIBXML="2.9.9" LIBJSON="0.12" LIBPROTOBUF="1.2.1" WAGYU="0.5.0 (Internal)" TOPOLOGY RASTER

and it works:

SELECT ST_Astext(
         ST_Transform(
           ST_SetSRID(geometry('POINT(-100 40 100)'),7406), 
           5500));
		   

outputs

POINT Z (-100.00041762022582 40.00000948365179 30.480060960121918)

Still a bit scary though that it crashes the server when it can't find the grid files

Note this is related to #4766 but scary that in order to see something is wrong, I have to have raster installed. We need better checking of proj in PostGIS proper and also for it not to crash if it can't find files.

comment:2 by pramsey, 3 years ago

I cannot replicate. If I strip away all the contents of /usr/local/share/proj, I get this error

SELECT ST_Astext(
         ST_Transform(
           ST_SetSRID(geometry('POINT(-100 40 100)'),7406), 
           5500));
ERROR:  proj_crs_is_swapped: proj_crs_get_coordinate_system returned NULL

but that's because I stripped away the EPSG database as well as all the grid files. If I return just the proj.db, I get a result, no sadness.

SELECT ST_Astext(
         ST_Transform(
           ST_SetSRID(geometry('POINT(-100 40 100)'),7406), 
           5500));
                             st_astext                              
--------------------------------------------------------------------
 POINT Z (-100.00041762022582 40.00000948365177 30.480060960121918)

comment:3 by robe, 3 years ago

Okay here is the backtrace I get

Thread 1 received signal SIGSEGV, Segmentation fault.
[Switching to Thread 18552.0x52d4]
0x000000006db780e0 in libproj-15!_ZNK5osgeo4proj2io16AuthorityFactory15databaseContextEv ()
   from C:\ming64gcc81\projects\proj\rel-6.3.2w64gcc81\bin\libproj-15.dll
(gdb) bt
#0  0x000000006db780e0 in libproj-15!_ZNK5osgeo4proj2io16AuthorityFactory15databaseContextEv ()
   from C:\ming64gcc81\projects\proj\rel-6.3.2w64gcc81\bin\libproj-15.dll
#1  0x000000006db368fe in libproj-15!_ZN5osgeo4proj9operation26CoordinateOperationFactory7Private34createOperationsCompoundToCompoundERKN7dropbox6oxygen2nnISt10shared_ptrINS0_3crs3CRSEEEESD_RNS3_7ContextEPKNS8_11CompoundCRSESI_RSt6vectorINS6_IS7_INS1_19CoordinateOperationEEEESaISM_EE ()
   from C:\ming64gcc81\projects\proj\rel-6.3.2w64gcc81\bin\libproj-15.dll
#2  0x000000006db2f4af in libproj-15!_ZN5osgeo4proj9operation26CoordinateOperationFactory7Private16createOperationsERKN7dropbox6oxygen2nnISt10shared_ptrINS0_3crs3CRSEEEESD_RNS3_7ContextE ()
   from C:\ming64gcc81\projects\proj\rel-6.3.2w64gcc81\bin\libproj-15.dll
#3  0x000000006db37e39 in libproj-15!_ZNK5osgeo4proj9operation26CoordinateOperationFactory16createOperationsERKN7dropbox6oxygen2nnISt10shared_ptrINS0_3crs3CRSEEEESC_RKNS5_ISt10unique_ptrINS1_26CoordinateOperationContextESt14default_deleteISE_EEEE ()
   from C:\ming64gcc81\projects\proj\rel-6.3.2w64gcc81\bin\libproj-15.dll
#4  0x000000006dba060a in proj_create_operations ()
   from C:\ming64gcc81\projects\proj\rel-6.3.2w64gcc81\bin\libproj-15.dll
#5  0x000000006dc0b180 in proj_create_crs_to_crs_from_pj ()
   from C:\ming64gcc81\projects\proj\rel-6.3.2w64gcc81\bin\libproj-15.dll
#6  0x000000006dc0b8bd in proj_create_crs_to_crs ()
   from C:\ming64gcc81\projects\proj\rel-6.3.2w64gcc81\bin\libproj-15.dll
#7  0x000000006f009b6b in AddToPROJSRSCache (srid_to=5500, srid_from=7406,
    PROJCache=0x80d83a8, fcinfo=0x80d7cf8) at lwgeom_transform.c:397
#8  GetPJUsingFCInfo (fcinfo=fcinfo@entry=0x80d7cf8, srid_from=7406,
    srid_to=srid_to@entry=5500, pj=pj@entry=0x4d7e6a8)
    at lwgeom_transform.c:505
#9  0x000000006efe43f9 in transform (fcinfo=0x80d7cf8)
    at lwgeom_transform.c:76
#10 0x00000000005ed01e in ExecInterpExpr (state=0x80d7c08,
    econtext=0x80d7e48, isnull=<optimized out>) at execExprInterp.c:699
#11 0x00000000006bf1e1 in ExecEvalExprSwitchContext (isNull=0x4d7e7dc,
    econtext=<optimized out>, state=0x80d7c08)
    at ../../../../src/include/executor/executor.h:313
#12 evaluate_expr (expr=<optimized out>,
    result_type=result_type@entry=798902,
    result_typmod=result_typmod@entry=-1,
    result_collation=result_collation@entry=0) at clauses.c:4792
#13 0x00000000006c0a98 in evaluate_function (context=0x4d7eec0,
    func_tuple=0x804f3b0, funcvariadic=false, args=0x80eae20, input_collid=0,
    result_collid=0, result_typmod=-1, result_type=798902, funcid=799233)
    at clauses.c:4323
#14 simplify_function (funcid=799233, result_type=798902, result_typmod=-1,
    result_collid=result_collid@entry=0, input_collid=input_collid@entry=0,
    args_p=args_p@entry=0x4d7e9c0, funcvariadic=funcvariadic@entry=false,
    process_args=process_args@entry=true,
    allow_non_const=allow_non_const@entry=true,
    context=context@entry=0x4d7eec0) at clauses.c:3953
#15 0x00000000006bf5f2 in eval_const_expressions_mutator (node=0x80ea328,
    context=0x4d7eec0) at clauses.c:2507
#16 0x000000000065f8e5 in expression_tree_mutator (node=0x80ea380,
    mutator=mutator@entry=0x6bf280 <eval_const_expressions_mutator>,
    context=context@entry=0x4d7eec0) at nodeFuncs.c:3059
#17 0x00000000006c10f9 in simplify_function (funcid=799486, result_type=25,
    result_typmod=-1, result_collid=result_collid@entry=100,
    input_collid=input_collid@entry=0, args_p=args_p@entry=0x4d7ec00,
    funcvariadic=funcvariadic@entry=false,
    process_args=process_args@entry=true,
    allow_non_const=allow_non_const@entry=true,
    context=context@entry=0x4d7eec0) at clauses.c:3944
#18 0x00000000006bf5f2 in eval_const_expressions_mutator (node=0x80ea538,
    context=0x4d7eec0) at clauses.c:2507
#19 0x000000000065ef04 in expression_tree_mutator (node=node@entry=0x80ea590,
    mutator=mutator@entry=0x6bf280 <eval_const_expressions_mutator>,
    context=context@entry=0x4d7eec0) at nodeFuncs.c:3180
#20 0x00000000006bf2d2 in eval_const_expressions_mutator (node=0x80ea590,
    context=0x4d7eec0) at clauses.c:3572
#21 0x000000000065f8e5 in expression_tree_mutator (node=node@entry=0x80ea5e8,
    mutator=mutator@entry=0x6bf280 <eval_const_expressions_mutator>,
    context=context@entry=0x4d7eec0) at nodeFuncs.c:3059
#22 0x00000000006bf2d2 in eval_const_expressions_mutator (node=0x80ea5e8,
    context=context@entry=0x4d7eec0) at clauses.c:3572
#23 0x00000000006c0904 in eval_const_expressions (root=root@entry=0x80ea6f0,
    node=<optimized out>) at clauses.c:2299
#24 0x00000000006a4208 in preprocess_expression (root=root@entry=0x80ea6f0,
    expr=<optimized out>, kind=kind@entry=1) at planner.c:1094
#25 0x00000000006abe14 in subquery_planner (glob=glob@entry=0x7775570,
    parse=<optimized out>, parse@entry=0x7775688,
    parent_root=parent_root@entry=0x0, hasRecursion=hasRecursion@entry=false,
    tuple_fraction=tuple_fraction@entry=0) at planner.c:771
#26 0x00000000006ad7ef in standard_planner (parse=0x7775688,
    query_string=<optimized out>, cursorOptions=256,
    boundParams=<optimized out>) at planner.c:405
#27 0x00000000007825ea in pg_plan_query (querytree=0x7775688,
    query_string=0x7774200 "SELECT ST_Astext(\n         ST_Transform(\n", ' ' <repeats 11 times>, "ST_SetSRID(geometry('POINT(-100 40 100)'),7406), \n", ' ' <repeats 11 times>, "5500));\n", ' ' <repeats 21 times>, cursorOptions=256,
    boundParams=0x0) at postgres.c:875
#28 0x00000000007826f1 in pg_plan_queries (querytrees=0x80ea698,
    query_string=query_string@entry=0x7774200 "SELECT ST_Astext(\n         ST_Transform(\n", ' ' <repeats 11 times>, "ST_SetSRID(geometry('POINT(-100 40 100)'),7406), \n", ' ' <repeats 11 times>, "5500));\n", ' ' <repeats 21 times>,
    cursorOptions=cursorOptions@entry=256, boundParams=boundParams@entry=0x0)
    at postgres.c:966
#29 0x0000000000782a80 in exec_simple_query (
    query_string=0x7774200 "SELECT ST_Astext(\n         ST_Transform(\n", ' ' <repeats 11 times>, "ST_SetSRID(geometry('POINT(-100 40 100)'),7406), \n", ' ' <repeats 11 times>, "5500));\n", ' ' <repeats 21 times>) at postgres.c:1158
#30 0x00000000007844b9 in PostgresMain (argc=<optimized out>,
    argv=argv@entry=0x77003e8, dbname=<optimized out>,
    username=<optimized out>) at postgres.c:4315
#31 0x00000000006f9cde in BackendRun (port=0x4d7f7c0, port=0x4d7f7c0)
    at postmaster.c:4536
#32 SubPostmasterMain (argc=argc@entry=3, argv=argv@entry=0x5d86ba0)
    at postmaster.c:5059
#33 0x00000000009123cf in main (argc=3, argv=0x5d86ba0) at main.c:187

Looks like it's crashing in proj. I'll try a newer proj to see if I can fair better.

comment:4 by robe, 3 years ago

Version: master3.0.x

comment:5 by robe, 3 years ago

sadly crashes with proj 7.1.1 too if I misstate PROJ_LIB.

Thread 1 received signal SIGSEGV, Segmentation fault.
[Switching to Thread 8320.0x1d04]
0x000000000819ec70 in libproj-19!_ZNK5osgeo4proj2io16AuthorityFactory15databaseContextEv ()
   from C:\ming64gcc81\projects\proj\rel-7.1.1w64gcc81\bin\libproj-19.dll
(gdb) bt
#0  0x000000000819ec70 in libproj-19!_ZNK5osgeo4proj2io16AuthorityFactory15databaseContextEv ()
   from C:\ming64gcc81\projects\proj\rel-7.1.1w64gcc81\bin\libproj-19.dll
#1  0x000000000815be0e in libproj-19!_ZN5osgeo4proj9operation26CoordinateOperationFactory7Private34createOperationsCompoundToCompoundERKN7dropbox6oxygen2nnISt10shared_ptrINS0_3crs3CRSEEEESD_RNS3_7ContextEPKNS8_11CompoundCRSESI_RSt6vectorINS6_IS7_INS1_19CoordinateOperationEEEESaISM_EE ()
   from C:\ming64gcc81\projects\proj\rel-7.1.1w64gcc81\bin\libproj-19.dll
#2  0x0000000008154648 in libproj-19!_ZN5osgeo4proj9operation26CoordinateOperationFactory7Private16createOperationsERKN7dropbox6oxygen2nnISt10shared_ptrINS0_3crs3CRSEEEESD_RNS3_7ContextE ()
   from C:\ming64gcc81\projects\proj\rel-7.1.1w64gcc81\bin\libproj-19.dll
#3  0x000000000815d399 in libproj-19!_ZNK5osgeo4proj9operation26CoordinateOperationFactory16createOperationsERKN7dropbox6oxygen2nnISt10shared_ptrINS0_3crs3CRSEEEESC_RKNS5_ISt10unique_ptrINS1_26CoordinateOperationContextESt14default_deleteISE_EEEE ()
   from C:\ming64gcc81\projects\proj\rel-7.1.1w64gcc81\bin\libproj-19.dll
#4  0x00000000081cbc98 in proj_create_operations ()
   from C:\ming64gcc81\projects\proj\rel-7.1.1w64gcc81\bin\libproj-19.dll
#5  0x000000000824033b in proj_create_crs_to_crs_from_pj ()
   from C:\ming64gcc81\projects\proj\rel-7.1.1w64gcc81\bin\libproj-19.dll
#6  0x00000000082407ed in proj_create_crs_to_crs ()
   from C:\ming64gcc81\projects\proj\rel-7.1.1w64gcc81\bin\libproj-19.dll
#7  0x000000006f009b6b in AddToPROJSRSCache (srid_to=5500, srid_from=7406,
    PROJCache=0x7fcfaf8, fcinfo=0x7fcf448) at lwgeom_transform.c:397
#8  GetPJUsingFCInfo (fcinfo=fcinfo@entry=0x7fcf448, srid_from=7406,
    srid_to=srid_to@entry=5500, pj=pj@entry=0x4d7e6a8)
    at lwgeom_transform.c:505
#9  0x000000006efe43f9 in transform (fcinfo=0x7fcf448)
    at lwgeom_transform.c:76
#10 0x00000000005ed01e in ExecInterpExpr (state=0x7fcf358,
    econtext=0x7fcf598, isnull=<optimized out>) at execExprInterp.c:699
#11 0x00000000006bf1e1 in ExecEvalExprSwitchContext (isNull=0x4d7e7dc,
    econtext=<optimized out>, state=0x7fcf358)
    at ../../../../src/include/executor/executor.h:313
#12 evaluate_expr (expr=<optimized out>,
    result_type=result_type@entry=798902,
    result_typmod=result_typmod@entry=-1,
    result_collation=result_collation@entry=0) at clauses.c:4792
#13 0x00000000006c0a98 in evaluate_function (context=0x4d7eec0,
    func_tuple=0x7f4f3b0, funcvariadic=false, args=0x7fea5b0, input_collid=0,
    result_collid=0, result_typmod=-1, result_type=798902, funcid=799233)
    at clauses.c:4323
#14 simplify_function (funcid=799233, result_type=798902, result_typmod=-1,
    result_collid=result_collid@entry=0, input_collid=input_collid@entry=0,
    args_p=args_p@entry=0x4d7e9c0, funcvariadic=funcvariadic@entry=false,
    process_args=process_args@entry=true,
    allow_non_const=allow_non_const@entry=true,
    context=context@entry=0x4d7eec0) at clauses.c:3953
#15 0x00000000006bf5f2 in eval_const_expressions_mutator (node=0x7fe9ab8,
    context=0x4d7eec0) at clauses.c:2507
#16 0x000000000065f8e5 in expression_tree_mutator (node=0x7fe9b10,
    mutator=mutator@entry=0x6bf280 <eval_const_expressions_mutator>,
    context=context@entry=0x4d7eec0) at nodeFuncs.c:3059
#17 0x00000000006c10f9 in simplify_function (funcid=799486, result_type=25,
    result_typmod=-1, result_collid=result_collid@entry=100,
    input_collid=input_collid@entry=0, args_p=args_p@entry=0x4d7ec00,
    funcvariadic=funcvariadic@entry=false,
    process_args=process_args@entry=true,
    allow_non_const=allow_non_const@entry=true,
    context=context@entry=0x4d7eec0) at clauses.c:3944
#18 0x00000000006bf5f2 in eval_const_expressions_mutator (node=0x7fe9cc8,
    context=0x4d7eec0) at clauses.c:2507
#19 0x000000000065ef04 in expression_tree_mutator (node=node@entry=0x7fe9d20,
    mutator=mutator@entry=0x6bf280 <eval_const_expressions_mutator>,
    context=context@entry=0x4d7eec0) at nodeFuncs.c:3180
#20 0x00000000006bf2d2 in eval_const_expressions_mutator (node=0x7fe9d20,
    context=0x4d7eec0) at clauses.c:3572
#21 0x000000000065f8e5 in expression_tree_mutator (node=node@entry=0x7fe9d78,
    mutator=mutator@entry=0x6bf280 <eval_const_expressions_mutator>,
    context=context@entry=0x4d7eec0) at nodeFuncs.c:3059
#22 0x00000000006bf2d2 in eval_const_expressions_mutator (node=0x7fe9d78,
    context=context@entry=0x4d7eec0) at clauses.c:3572
#23 0x00000000006c0904 in eval_const_expressions (root=root@entry=0x7fe9e80,
    node=<optimized out>) at clauses.c:2299
#24 0x00000000006a4208 in preprocess_expression (root=root@entry=0x7fe9e80,
    expr=<optimized out>, kind=kind@entry=1) at planner.c:1094
#25 0x00000000006abe14 in subquery_planner (glob=glob@entry=0x7675570,
    parse=<optimized out>, parse@entry=0x7675688,
    parent_root=parent_root@entry=0x0, hasRecursion=hasRecursion@entry=false,
    tuple_fraction=tuple_fraction@entry=0) at planner.c:771
#26 0x00000000006ad7ef in standard_planner (parse=0x7675688,
    query_string=<optimized out>, cursorOptions=256,
    boundParams=<optimized out>) at planner.c:405
#27 0x00000000007825ea in pg_plan_query (querytree=0x7675688,
    query_string=0x7674200 "SELECT ST_Astext(\n         ST_Transform(\n", ' ' <repeats 11 times>, "ST_SetSRID(geometry('POINT(-100 40 100)'),7406), \n", ' ' <repeats 11 times>, "5500));\n", ' ' <repeats 21 times>, cursorOptions=256,
    boundParams=0x0) at postgres.c:875
#28 0x00000000007826f1 in pg_plan_queries (querytrees=0x7fe9e28,
    query_string=query_string@entry=0x7674200 "SELECT ST_Astext(\n         ST_Transform(\n", ' ' <repeats 11 times>, "ST_SetSRID(geometry('POINT(-100 40 100)'),7406), \n", ' ' <repeats 11 times>, "5500));\n", ' ' <repeats 21 times>,
    cursorOptions=cursorOptions@entry=256, boundParams=boundParams@entry=0x0)
    at postgres.c:966
#29 0x0000000000782a80 in exec_simple_query (
    query_string=0x7674200 "SELECT ST_Astext(\n         ST_Transform(\n", ' ' <repeats 11 times>, "ST_SetSRID(geometry('POINT(-100 40 100)'),7406), \n", ' ' <repeats 11 times>, "5500));\n", ' ' <repeats 21 times>) at postgres.c:1158
#30 0x00000000007844b9 in PostgresMain (argc=<optimized out>,
    argv=argv@entry=0x76003e8, dbname=<optimized out>,
    username=<optimized out>) at postgres.c:4315
#31 0x00000000006f9cde in BackendRun (port=0x4d7f7c0, port=0x4d7f7c0)
    at postmaster.c:4536
#32 SubPostmasterMain (argc=argc@entry=3, argv=argv@entry=0x5af6ba0)
    at postmaster.c:5059
#33 0x00000000009123cf in main (argc=3, argv=0x5af6ba0) at main.c:187

comment:6 by pramsey, 3 years ago

I'd suggest rather than letting this ticket languish in our system that you find out a commandline example using the 'proj' binary you built under windows and make it fail there, then report it upstream.

comment:7 by robe, 3 years ago

Resolution: wontfix
Status: newclosed

okay - it's more or less a non-issue anyway for 3.0.3 and above since I added the proj_lib

Note: See TracTickets for help on using tickets.