diff --git a/libmamba/src/api/configuration.cpp b/libmamba/src/api/configuration.cpp index 110a302efd..d065e396e9 100644 --- a/libmamba/src/api/configuration.cpp +++ b/libmamba/src/api/configuration.cpp @@ -2338,6 +2338,14 @@ namespace mamba strStream << inFile.rdbuf(); std::string s = strStream.str(); config = YAML::Load(expandvars(s)); + if (config.IsScalar()) + { + LOG_WARNING << fmt::format( + "The configuration file at {} is misformatted or corrupted. Skipping file.", + file.string() + ); + return YAML::Node(); + } } catch (const std::exception& ex) { diff --git a/libmamba/tests/src/core/test_configuration.cpp b/libmamba/tests/src/core/test_configuration.cpp index a221f0f6d3..60baf04254 100644 --- a/libmamba/tests/src/core/test_configuration.cpp +++ b/libmamba/tests/src/core/test_configuration.cpp @@ -918,6 +918,15 @@ namespace mamba util::unset_env("MAMBA_CHANNEL_PRIORITY"); } + TEST_CASE_FIXTURE(Configuration, "skip_misformatted_config_file") + { + std::string rc = "invalid_scalar_value"; + load_test_config(rc); + CHECK_EQ(config.sources().size(), 1); + CHECK_EQ(config.valid_sources().size(), 0); + CHECK_EQ(config.dump(), ""); + } + TEST_CASE_FIXTURE(Configuration, "pinned_packages") { std::string rc1 = unindent(R"(