#30274: Segfault on iteration of GEOS Polygons/LinearRings
-------------------------------------+-------------------------------------
               Reporter:  Murray     |          Owner:  nobody
  Christopherson                     |
                   Type:  Bug        |         Status:  new
              Component:  GIS        |        Version:  2.1
               Severity:  Normal     |       Keywords:  geos gis
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 **Environment Details**
 Ubuntu 14.04 (trusty)
 Python 3.6.8 (via package manager, unofficial repo: ppa:deadsnakes/ppa)
 Django 2.1.7 (via pip)
 libgeos (both 3.4.2 via apt-get, and 3.7.1 via source distribution)

 First and foremost, I am aware that the OS is a bit older (hence the
 unofficial installation routes of some newer dependencies), but I was
 unable to find any reason these components shouldn't play nice.

 **Steps to reproduce**
 I have a minimal script showcasing the issue:

 {{{
 from django.contrib.gis.geos import Polygon

 def main():
     polygon = Polygon( ((0.0, 0.0), (0.0, 50.0), (50.0, 50.0), (50.0,
 0.0), (0.0, 0.0)) )

     for p in polygon[0]:
         print('Longitude:', p[0])
         print('Latitude:', p[1])

 if __name__ == '__main__':
     main()
 }}}

 **Expected Behaviour**
 Output to stdout, something like:

 {{{
 Latitude: 0.0
 Longitude: 0.0
 Latitude: 0.0
 Longitude: 50.0
 ...
 }}}

 **Observed Behaviour**
 Output to stderr:

 {{{
 Segmentation fault (core dumped)
 }}}

 **Notes**
 It should be noted, when originally observed, there was a stacktrace
 (which I won't post in full, as it's mostly uWSGI functions), but the
 relevant section suggested the segfault is in `GEOSCoordSeq_getSize` in
 `libgeos.so`, which leads me to believe the issue may be in
 
https://github.com/django/django/blob/master/django/contrib/gis/geos/prototypes/coordseq.py.

 Furthermore, this issue was uncovered during a Python 2 to 3 migration
 attempt. The issue did not manifest in this environment:
 Ubuntu 14.04 (trusty)
 Python 2.7.12 (via package manager, unofficial repo: ppa:deadsnakes/ppa)
 Django 1.11.18 (via pip)
 libgeos 3.4.2 (via apt-get)

 Lastly, I was able to find a workaround (in case anyone else encounters
 this). This un-Pythonic variation seems to work:

 {{{
 from django.contrib.gis.geos import Polygon

 def main():
     polygon = Polygon( ((0.0, 0.0), (0.0, 50.0), (50.0, 50.0), (50.0,
 0.0), (0.0, 0.0)) )

     for i in range(len(polygon[0])):
         p = polygon[0][i]
         print('Longitude:', p[0])
         print('Latitude:', p[1])

 if __name__ == '__main__':
     main()
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30274>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.55e6d30798931d3fcac28acf9a823672%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to