From 68b216f821ab34aab3441e148af3135ad3c84be9 Mon Sep 17 00:00:00 2001 From: Caleb Krause Date: Sat, 4 Apr 2026 21:38:43 -0500 Subject: [PATCH] Add bounds verification in parseNext --- happly.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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;