From c3ccff4f022cac728378d394f6300b5e424509a2 Mon Sep 17 00:00:00 2001 From: artemp Date: Wed, 21 Oct 2015 16:33:12 +0100 Subject: [PATCH] shape.input - add stream state check and calculate position limit --- plugins/input/shape/shape_featureset.cpp | 3 ++- plugins/input/shape/shapefile.hpp | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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