bilaldursun1 / nettopologysuite

Automatically exported from code.google.com/p/nettopologysuite
0 stars 0 forks source link

Bug: If a shape file is corrupted, ShapefileReader throws an error but the file is locked. #178

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Take any corrupted shape file (with .shp extension).
2. Create ShapfileReader on this shape file.
3. The error "The first four bytes of this file indicate this is not a shape 
file." is thrown.
4. The shape file is locked unless application shuts down.

What is the expected output? What do you see instead?
ShapfileReader should release the shape file so that our application can handle 
the file.

What version of the product are you using? On what operating system?
1.13.1.0 on Windows 8.

Please provide any additional information below.
In the NetTopologySuite.IO.ShapefileReader constructor, suggest to change the 
following code block:
var stream = new FileStream(filename, FileMode.Open, FileAccess.Read, 
FileShare.Read);
var shpBinaryReader = new BigEndianBinaryReader(stream);
_mainHeader = new ShapefileHeader(shpBinaryReader);
shpBinaryReader.Close();

to:

using(var stream = new FileStream(filename, FileMode.Open, FileAccess.Read, 
FileShare.Read))
{
   using(var shpBinaryReader = new BigEndianBinaryReader(stream))
   {
      _mainHeader = new ShapefileHeader(shpBinaryReader);
   }
}

Original issue reported on code.google.com by MingD...@trimblegeospatial.com on 18 Mar 2014 at 4:21

GoogleCodeExporter commented 9 years ago
Can you attach a sample corrupted shapefile, so I can test your proposed change?
Thanks :)

Original comment by diegogu...@gmail.com on 18 Mar 2014 at 4:38

GoogleCodeExporter commented 9 years ago
See the attachment.

Original comment by MingD...@trimblegeospatial.com on 18 Mar 2014 at 8:56

Attachments:

GoogleCodeExporter commented 9 years ago
I'm unable to reproduce the problem in a test. Anyway your code looks good, so 
I have commit the patch with r1196.
Can you verify if this code fix your problem? Maybe you can suggest how I can 
improve the fixture: http://goo.gl/delqzt
Thanks for the patch.

Original comment by diegogu...@gmail.com on 18 Mar 2014 at 10:56

GoogleCodeExporter commented 9 years ago
We are currently using NuGet to get NTS - Topology Suite package.  We do not 
compile the source codes locally. Could we get the patch by NuGet?

Thanks,

-Ming

Original comment by MingD...@trimblegeospatial.com on 24 Mar 2014 at 10:26

GoogleCodeExporter commented 9 years ago
no plans to release a new nuget package soon, sorry. 
you can easily build your own version from the trunk and reference this version 
direclty.

Original comment by diegogu...@gmail.com on 26 Mar 2014 at 12:33