Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/AppInstallerCLITests/AppInstallerCLITests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,9 @@
<CopyFileToFolders Include="TestData\ContainsEscapeControlCode.yaml">
<DeploymentContent>true</DeploymentContent>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\ContainsTooManyNestedLayers.yaml">
<DeploymentContent>true</DeploymentContent>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\ManifestV1_10-Bad-SchemaHeaderInvalid.yaml">
<DeploymentContent>true</DeploymentContent>
</CopyFileToFolders>
Expand Down
3 changes: 3 additions & 0 deletions src/AppInstallerCLITests/AppInstallerCLITests.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,9 @@
<CopyFileToFolders Include="TestData\ContainsEscapeControlCode.yaml">
<Filter>TestData</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\ContainsTooManyNestedLayers.yaml">
<Filter>TestData</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\ManifestV1_10-Bad-SchemaHeaderInvalid.yaml">
<Filter>TestData</Filter>
</CopyFileToFolders>
Expand Down
101 changes: 101 additions & 0 deletions src/AppInstallerCLITests/TestData/ContainsTooManyNestedLayers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- value
5 changes: 5 additions & 0 deletions src/AppInstallerCLITests/Yaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,8 @@ TEST_CASE("YamlContainsEscapeControlCode", "[YAML]")
{
REQUIRE_THROWS_HR(Load(TestDataFile("ContainsEscapeControlCode.yaml")), APPINSTALLER_CLI_ERROR_LIBYAML_ERROR);
}

TEST_CASE("YamlContainsTooManyNestedLayers", "[YAML]")
{
REQUIRE_THROWS_HR(Load(TestDataFile("ContainsTooManyNestedLayers.yaml")), APPINSTALLER_CLI_ERROR_YAML_DOC_BUILD_FAILED);
}
19 changes: 19 additions & 0 deletions src/AppInstallerSharedLib/YamlWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ namespace AppInstaller::YAML::Wrapper
size_t childOffset = 0;
};

static int YAML_DOCUMENT_NEST_LEVEL_LIMIT = 100;
int nestLevel = 0;

std::stack<StackItem> resultStack;
resultStack.emplace(root, &result);

Expand All @@ -173,6 +176,12 @@ namespace AppInstaller::YAML::Wrapper
break;
case YAML_SEQUENCE_NODE:
{
if (stackItem.childOffset == 0)
{
// We've entered the sequence.
nestLevel++;
}

yaml_node_item_t* child = stackItem.yamlNode->data.sequence.items.start + stackItem.childOffset++;
if (child < stackItem.yamlNode->data.sequence.items.top)
{
Expand All @@ -184,11 +193,18 @@ namespace AppInstaller::YAML::Wrapper
{
// We've reached the end of the sequence
pop = true;
nestLevel--;
}
break;
}
case YAML_MAPPING_NODE:
{
if (stackItem.childOffset == 0)
{
// We've entered the mapping.
nestLevel++;
}

yaml_node_pair_t* child = stackItem.yamlNode->data.mapping.pairs.start + stackItem.childOffset++;
if (child < stackItem.yamlNode->data.mapping.pairs.top)
{
Expand All @@ -207,6 +223,7 @@ namespace AppInstaller::YAML::Wrapper
{
// We've reached the end of the mapping
pop = true;
nestLevel--;
}
break;
}
Expand All @@ -216,6 +233,8 @@ namespace AppInstaller::YAML::Wrapper
{
resultStack.pop();
}

THROW_HR_IF_MSG(APPINSTALLER_CLI_ERROR_YAML_DOC_BUILD_FAILED, nestLevel > YAML_DOCUMENT_NEST_LEVEL_LIMIT, "Too many layers of nested nodes.");
}

return result;
Expand Down
Loading