GeospatialPython / pyshp

This library reads and writes ESRI Shapefiles in pure Python.
MIT License
1.1k stars 260 forks source link

Writer crashes for empty POLYGONZ or POLYLINEZ file #213

Closed kad-vliegr closed 3 years ago

kad-vliegr commented 3 years ago

Writer crashes for POLYGONZ or POLYLINEZ files if there are no points. It crashes in __shapefileHeader() when it tries to write the following:

        try:
            f.write(pack("<4d", zbox[0], zbox[1], mbox[0], mbox[1]))

Reason for the crash: zbox and mbox are None and thus not subscriptable.

Edit: Example program to trigger the bug:

import os
import tempfile
import shapefile

with tempfile.TemporaryDirectory() as tmpdir:
    with shapefile.Writer(os.path.join(tmpdir, 'test.shp')) as writer:
        writer.shapeType = shapefile.POLYGONZ
karimbahgat commented 3 years ago

This sounds like the same as #188, and should be fixed in the latest version 2.1.3. What version are you on?

kad-vliegr commented 3 years ago

Yes, it seems you are right. Apparently the machine on which the bug triggered was still on version 2.1.2.