calvinmetcalf / shapefile-js

Convert a Shapefile to GeoJSON. Not many caveats.
http://calvinmetcalf.github.io/shapefile-js/
715 stars 228 forks source link

It trips on incorrect file size #100

Closed TonyTNguyen closed 2 years ago

TonyTNguyen commented 5 years ago

I understand that the shape file has to be compliant with the specification, but once a while, I think a little tolerance won't hurt. My case is the file https://ufile.io/ekyn4 (file valid only 30 days from 8/2/2018) I debug the latest shp.js, and open the .shp file with the hex editor, and find out that the header say the file size should be 652 bytes, but the actual size is 656 bytes. So it trips on checkOffset(offset, ext, length) inside readInt32BE(), when the offset === 652 of ParseShp.prototype.getRow = function(offset) {...} view return on "var view = this.buffer.slice(offset, offset + 12);" only 4 bytes, so the next line var len = view.readInt32BE(4) << 1; will raise error inside readInt32BE().

There is function ParseShp.prototype.parseHeader that will able to to return the length that we need. We can use that while advance the buffer inside of ParseShp.prototype.getRows() instead rely on the size of the buffer. Then we can be tolerance when the actual size is larger that stated size is.

calvinmetcalf commented 5 years ago

file is attached for posterity, ok let me look into this ipra_dresden_03.zip

calvinmetcalf commented 5 years ago

ok see #101 basically it was actually more then just the file being too long, there was a cutoff record that started before the file was supposed to end

calvinmetcalf commented 2 years ago

fixed in 4.0.2