Skip to content

Limit YAML alias expansion to prevent excessive memory use - #6685

Merged
AmirMS (AmelBawa-msft) merged 3 commits into
microsoft:masterfrom
AmelBawa-msft:user/amelbawa/fix-yaml-alias-expansion
Nov 17, 2026
Merged

AmirMS (AmelBawa-msft) merged 3 commits into
microsoft:masterfrom
AmelBawa-msft:user/amelbawa/fix-yaml-alias-expansion

Conversation

@AmelBawa-msft

@AmelBawa-msft AmirMS (AmelBawa-msft) commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

📖 Description

Document::GetRoot() copies the anchored node each time an alias refers to it. Nested aliases can make a tiny YAML file expand to millions of nodes and use hundreds of MB.

It now tracks which document nodes it has already converted. Any repeat visit is an alias copy, which counts its node size plus its tag and scalar length. Once alias copies add more than 10 MiB, loading fails with APPINSTALLER_CLI_ERROR_YAML_DOC_BUILD_FAILED. Files under the limit load as before.

🔗 References

🔍 Validation

✅ Checklist

🤖 AI Assistance

  • AI assistance was used and has been disclosed in this PR
  • No AI assistance was used

📋 Issue Type

  • Bug fix
  • Feature
  • Task
Microsoft Reviewers: Open in CodeFlow

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new 10 MiB YAML alias-expansion limit introduces a user-visible loading restriction without the required release-note fragment.

1 open issue
What changed in this PR

This PR limits YAML alias expansion in WinGet’s shared YAML loader to prevent excessive memory use. Documents exceeding the 10 MiB alias-copy budget now fail with APPINSTALLER_CLI_ERROR_YAML_DOC_BUILD_FAILED.

Changes:

  • Track repeated document-node visits and count copied node, tag, and scalar data.
  • Add tests for supported aliases, excessive nested expansion, and large aliased values.
File Description
src/​AppInstallerSharedLib/​YamlWrapper.cpp Enforce the alias-copy budget during YAML conversion.
src/​AppInstallerCLITests/​Yaml.cpp Test normal alias handling and both expansion-limit scenarios.

Review effort: Balanced

@ranm-msft ranm-msft left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alias budget accounts for repeated mappings, sequences and scalar data without changing ordinary alias behavior. The benign-alias, large-scalar and small-node tests cover the important boundaries.

@AmelBawa-msft
AmirMS (AmelBawa-msft) merged commit b90eaad into microsoft:master Nov 17, 2026
9 checks passed
@AmelBawa-msft
AmirMS (AmelBawa-msft) deleted the user/amelbawa/fix-yaml-alias-expansion branch November 17, 2026 03:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants