pyproj4 / pyproj

Python interface to PROJ (cartographic projections and coordinate transformations library)
https://pyproj4.github.io/pyproj
MIT License
1.04k stars 211 forks source link

seg fault on CRS.to_authority for certain IAU projection codes #1319

Closed AndrewAnnex closed 1 year ago

AndrewAnnex commented 1 year ago

Code Sample, a copy-pastable example if possible

note it's easier to copy/paste the following into ipython

import pyproj
wkt = 'PROJCRS["Earth (2015) / Ocentric/ Equirectangular, clon = 0",BASEGEODCRS["Earth (2015) / Ocentric", DATUM["Earth (2015)", ELLIPSOID["Earth (2015)", 6378136.6, 298.25700617732406,LENGTHUNIT["metre", 1, ID["EPSG", 9001]]], ANCHOR["Greenwich : 0"]],PRIMEM["Reference Meridian", 0, ANGLEUNIT["degree", 0.0174532925199433, ID["EPSG", 9122]]], ID["IAU", 39902, 2015]],CONVERSION["Equirectangular, clon = 0", METHOD["Equidistant Cylindrical", ID["EPSG", 1028]], PARAMETER["Latitude of 1st standard parallel", 0, ANGLEUNIT["degree",0.0174532925199433,ID["EPSG", 9122]], ID["EPSG", 8823]], PARAMETER["Longitude of natural origin", 0, ANGLEUNIT["degree",0.0174532925199433,ID["EPSG", 9122]], ID["EPSG", 8802]], PARAMETER["False easting", 0, LENGTHUNIT["metre",1,ID["EPSG", 9001]], ID["EPSG", 8806]],PARAMETER["False northing", 0, LENGTHUNIT["metre",1,ID["EPSG", 9001]], ID["EPSG", 8807]]],CS[Cartesian, 2], AXIS["Easting (E)", east, ORDER[1], LENGTHUNIT["metre", 1]], AXIS["Northing (N)", north, ORDER[2], LENGTHUNIT["metre", 1]],ID["IAU", 39912, 2015]]'
crs = pyproj.CRS.from_wkt(wkt) 
print(crs.to_authority())
print('no segfault') # won't happen

Problem description

Pyproj (or more realistically proj underneath) seg faults when to_authority is called for some, but not all, IAU CRSs.

In the above code, the crs object is created but calling to_authority (or seemingly repr) causes a segmentation fault and termination of the python process.

Although the information I pasted below was for my m1 mac where I am developing, this issue is also happening in CI builds in ubuntu-latest: https://github.com/AndrewAnnex/planetcantile/actions/runs/5576629154/jobs/10188207849

So it looks like this is probably a relatively recently introduced issue as builds 2-3 months ago were working prior to the recent releases of PyProj/Proj.

Hopefully the call to to_authority is granular enough, due to the segfault it gets annoying to try to see if there is a more diagnostic function that could be used to debug proj from python-land so I haven't dug as deeply as may be possible.

Expected Output

not a seg fault

Environment Information

pyproj info: pyproj: 3.6.0 PROJ: 9.2.1 data dir: /Users/andrew/mambaforge/envs/morecantile/share/proj user_data_dir: /Users/andrew/Library/Application Support/proj PROJ DATA (recommended version): 1.14 PROJ Database: 1.2 EPSG Database: v10.088 [2023-05-13] ESRI Database: ArcGIS Pro 3.1 [2023-19-01] IGNF Database: 3.1.0 [2019-05-24]

System: python: 3.11.4 | packaged by conda-forge | (main, Jun 10 2023, 18:08:41) [Clang 15.0.7 ] executable: /Users/andrew/mambaforge/envs/morecantile/bin/python machine: macOS-13.4.1-arm64-arm-64bit

Python deps: certifi: 2023.5.7 Cython: None setuptools: 68.0.0 pip: 23.2

Installation method

conda (via mamba)

Conda environment information (if you installed with conda):

# packages in environment at /Users/andrew/mambaforge/envs/morecantile:
#
# Name                    Version                   Build  Channel
proj                      9.2.1                h8fdea58_0    conda-forge
pyproj                    3.6.0           py311h280d66e_1    conda-forge


Details about conda and system ( conda info ):

``` active environment : morecantile active env location : /Users/andrew/mambaforge/envs/morecantile shell level : 5 user config file : /Users/andrew/.condarc populated config files : /Users/andrew/mambaforge/.condarc conda version : 23.1.0 conda-build version : not installed python version : 3.10.10.final.0 virtual packages : __archspec=1=arm64 __osx=13.4.1=0 __unix=0=0 base environment : /Users/andrew/mambaforge (writable) conda av data dir : /Users/andrew/mambaforge/etc/conda conda av metadata url : None channel URLs : https://conda.anaconda.org/conda-forge/osx-arm64 https://conda.anaconda.org/conda-forge/noarch package cache : /Users/andrew/mambaforge/pkgs /Users/andrew/.conda/pkgs envs directories : /Users/andrew/mambaforge/envs /Users/andrew/.conda/envs platform : osx-arm64 user-agent : conda/23.1.0 requests/2.28.2 CPython/3.10.10 Darwin/22.5.0 OSX/13.4.1 UID:GID : 501:20 netrc file : None offline mode : False ```
snowman2 commented 1 year ago

To add internal PROJ debugging: https://pyproj4.github.io/pyproj/stable/advanced_examples.html#debugging-internal-proj

AndrewAnnex commented 1 year ago

@snowman2 didn't seem to help, I see a debug call to fopen for proj.ini which succeeds before the segfault

snowman2 commented 1 year ago
$ python debug.py 
Segmentation fault (core dumped)
$ gdb python
...
(gdb) run debug.py
Starting program:~/bin/python debug.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff6d90b90 in osgeo::proj::crs::GeographicCRS::coordinateSystem() const () from ~/lib/libproj.so.25
snowman2 commented 1 year ago
projinfo 'PROJCRS["Earth (2015) / Ocentric/ Equirectangular, clon = 0",BASEGEODCRS["Earth (2015) / Ocentric", DATUM["Earth (2015)", ELLIPSOID["Earth (2015)", 6378136.6, 298.25700617732406,LENGTHUNIT["metre", 1, ID["EPSG", 9001]]], ANCHOR["Greenwich : 0"]],PRIMEM["Reference Meridian", 0, ANGLEUNIT["degree", 0.0174532925199433, ID["EPSG", 9122]]], ID["IAU", 39902, 2015]],CONVERSION["Equirectangular, clon = 0", METHOD["Equidistant Cylindrical", ID["EPSG", 1028]], PARAMETER["Latitude of 1st standard parallel", 0, ANGLEUNIT["degree",0.0174532925199433,ID["EPSG", 9122]], ID["EPSG", 8823]], PARAMETER["Longitude of natural origin", 0, ANGLEUNIT["degree",0.0174532925199433,ID["EPSG", 9122]], ID["EPSG", 8802]], PARAMETER["False easting", 0, LENGTHUNIT["metre",1,ID["EPSG", 9001]], ID["EPSG", 8806]],PARAMETER["False northing", 0, LENGTHUNIT["metre",1,ID["EPSG", 9001]], ID["EPSG", 8807]]],CS[Cartesian, 2], AXIS["Easting (E)", east, ORDER[1], LENGTHUNIT["metre", 1]], AXIS["Northing (N)", north, ORDER[2], LENGTHUNIT["metre", 1]],ID["IAU", 39912, 2015]]' --identify -o PROJ
PROJ.4 string:
+proj=eqc +lat_ts=0 +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +a=6378136.6 +rf=298.257006177324 +units=m +no_defs +type=crs
Segmentation fault (core dumped)
snowman2 commented 1 year ago

Forwarded: https://github.com/OSGeo/PROJ/issues/3828

AndrewAnnex commented 1 year ago

Nice that you found more, I thought I was following the instructions well enough but didn’t know gdb would just work.- Dr. Andrew AnnexOn Jul 17, 2023, at 2:31 PM, Alan D. Snow @.***> wrote: Forwarded: OSGeo/PROJ#3828

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>