Skip to content

Conversation

riggsd
Copy link

@riggsd riggsd commented Dec 3, 2014

While pyshp is generally good about raising appropriate exceptions, it currently uses assert() in two places:

  • Possibly corrupted DBF header
  • User attempting to write larger value than a field allows for

Not only are these both examples of cases where assert() isn't appropriate, they're cases that could lead to data corruption if uncaught... and when CPython is invoked with -O or -OO, assert() conditions are never raised.

This patch raises a descriptive ShapefileException in these two cases.

@GeospatialPython
Copy link
Owner

Good call on this one. The dbf sections of the library are based on this simple recipe from the Python Cookbook: http://code.activestate.com/recipes/362715-dbf-reader-and-writer/

In fact I'm strongly considering replacing dbf handling with something like dbfpy. However I'd also like this library to stay a simple one-file library and not turn into a "shapefile framework".

GeospatialPython added a commit that referenced this pull request Jan 9, 2015
Don't Use Asserts For Runtime Errors
@GeospatialPython GeospatialPython merged commit be538eb into GeospatialPython:master Jan 9, 2015
@riggsd riggsd deleted the no-asserts branch February 3, 2015 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants