diff --git a/plugins/input/shape/shape_featureset.cpp b/plugins/input/shape/shape_featureset.cpp index 78ebb1da9..490fa3d5e 100644 --- a/plugins/input/shape/shape_featureset.cpp +++ b/plugins/input/shape/shape_featureset.cpp @@ -71,7 +71,8 @@ feature_ptr shape_featureset::next() return feature_ptr(); } - while (shape_.shx().pos() < 2 * shx_file_length_) + std::streampos position_limit = 2 * shx_file_length_ - 2 * sizeof(int); + while (shape_.shx().is_good() && shape_.shx().pos() <= position_limit) { int offset = shape_.shx().read_xdr_integer(); int record_length = shape_.shx().read_xdr_integer(); diff --git a/plugins/input/shape/shapefile.hpp b/plugins/input/shape/shapefile.hpp index 270ef939f..1c61df0b8 100644 --- a/plugins/input/shape/shapefile.hpp +++ b/plugins/input/shape/shapefile.hpp @@ -259,6 +259,11 @@ public: { return file_.eof(); } + + inline bool is_good() + { + return file_.good(); + } }; #endif // SHAPEFILE_HPP