Index: lib/Support/YAMLTraits.cpp =================================================================== --- lib/Support/YAMLTraits.cpp +++ lib/Support/YAMLTraits.cpp @@ -326,7 +326,12 @@ } else if (MappingNode *Map = dyn_cast(N)) { MapHNode *mapHNode = new MapHNode(N); for (KeyValueNode &KVN : *Map) { - ScalarNode *KeyScalar = dyn_cast(KVN.getKey()); + Node *KeyNode = KVN.getKey(); + ScalarNode *KeyScalar = dyn_cast(KeyNode); + if (!KeyScalar) { + setError(KeyNode, "Map key must be a scalar"); + break; + } StringStorage.clear(); StringRef KeyStr = KeyScalar->getValue(StringStorage); if (!StringStorage.empty()) { Index: unittests/Support/YAMLIOTest.cpp =================================================================== --- unittests/Support/YAMLIOTest.cpp +++ unittests/Support/YAMLIOTest.cpp @@ -84,6 +84,13 @@ } } +TEST(YAMLIO, TestMalformedMapRead) { + FooBar doc; + Input yin("{foo: 3; bar: 5}", nullptr, suppressErrorMessages); + yin >> doc; + EXPECT_TRUE(!!yin.error()); +} + // // Test the reading of a yaml sequence of mappings //