diff --git a/happly.h b/happly.h index 4ee8c71..daec490 100644 --- a/happly.h +++ b/happly.h @@ -316,6 +316,9 @@ class TypedProperty : public Property { * @param currEntry Index in to tokens, updated after this property is read. */ virtual void parseNext(const std::vector& tokens, size_t& currEntry) override { + if (currEntry >= tokens.size()) { + throw std::runtime_error("PLY parser: missing token for property"); + } data.emplace_back(); std::istringstream iss(tokens[currEntry]); typename SerializeType::type tmp; // usually the same type as T @@ -468,7 +471,9 @@ class TypedListProperty : public Property { * @param currEntry Index in to tokens, updated after this property is read. */ virtual void parseNext(const std::vector& tokens, size_t& currEntry) override { - + if (currEntry >= tokens.size()) { + throw std::runtime_error("PLY parser: missing token for property"); + } std::istringstream iss(tokens[currEntry]); size_t count; iss >> count; @@ -478,6 +483,9 @@ class TypedListProperty : public Property { size_t afterSize = currSize + count; flattenedData.resize(afterSize); for (size_t iFlat = currSize; iFlat < afterSize; iFlat++) { + if (currEntry >= tokens.size()) { + throw std::runtime_error("PLY parser: missing token for property"); + } std::istringstream iss(tokens[currEntry]); typename SerializeType::type tmp; // usually the same type as T iss >> tmp;