Index: lib/Support/YAMLTraits.cpp =================================================================== --- lib/Support/YAMLTraits.cpp +++ lib/Support/YAMLTraits.cpp @@ -112,7 +112,7 @@ } void Input::beginMapping() { - if (EC) + if (EC || Strm->failed()) return; // CurrentNode can be null if the document is empty. MapHNode *MN = dyn_cast_or_null(CurrentNode); @@ -124,7 +124,7 @@ bool Input::preflightKey(const char *Key, bool Required, bool, bool &UseDefault, void *&SaveInfo) { UseDefault = false; - if (EC) + if (EC || Strm->failed()) return false; // CurrentNode is null for empty documents, which is an error in case required @@ -159,7 +159,7 @@ } void Input::endMapping() { - if (EC) + if (EC || Strm->failed()) return; // CurrentNode can be null if the document is empty. MapHNode *MN = dyn_cast_or_null(CurrentNode); @@ -196,7 +196,7 @@ } bool Input::preflightElement(unsigned Index, void *&SaveInfo) { - if (EC) + if (EC || Strm->failed()) return false; if (SequenceHNode *SQ = dyn_cast(CurrentNode)) { SaveInfo = CurrentNode; @@ -213,7 +213,7 @@ unsigned Input::beginFlowSequence() { return beginSequence(); } bool Input::preflightFlowElement(unsigned index, void *&SaveInfo) { - if (EC) + if (EC || Strm->failed()) return false; if (SequenceHNode *SQ = dyn_cast(CurrentNode)) { SaveInfo = CurrentNode; @@ -271,7 +271,7 @@ } bool Input::bitSetMatch(const char *Str, bool) { - if (EC) + if (EC || Strm->failed()) return false; if (SequenceHNode *SQ = dyn_cast(CurrentNode)) { unsigned Index = 0; @@ -293,7 +293,7 @@ } void Input::endBitSetScalar() { - if (EC) + if (EC || Strm->failed()) return; if (SequenceHNode *SQ = dyn_cast(CurrentNode)) { assert(BitValuesUsed.size() == SQ->Entries.size()); @@ -342,7 +342,7 @@ auto SQHNode = llvm::make_unique(N); for (Node &SN : *SQ) { auto Entry = this->createHNodes(&SN); - if (EC) + if (EC || Strm->failed()) break; SQHNode->Entries.push_back(std::move(Entry)); } @@ -363,7 +363,7 @@ KeyStr = StringStorage.str().copy(StringAllocator); } auto ValueHNode = this->createHNodes(KVN.getValue()); - if (EC) + if (EC || Strm->failed()) break; mapHNode->Mapping[KeyStr] = std::move(ValueHNode); } Index: unittests/Support/YAMLIOTest.cpp =================================================================== --- unittests/Support/YAMLIOTest.cpp +++ unittests/Support/YAMLIOTest.cpp @@ -2368,3 +2368,11 @@ out); out.clear(); } + +TEST(YAMLIO, InvalidInput) { + // polluting 1 value in the sequence + Input yin("---\n- foo: 3\n bar: 5\n1\n- foo: 3\n bar: 5\n...\n"); + std::vector Data; + yin >> Data; + EXPECT_TRUE((bool)yin.error()); +}