Skip to content

fix(azure_policy): index only all-digit subscripts and saturate overflow - #869

Merged
Anand Krishnamoorthi (anakrish) merged 3 commits into
microsoft:mainfrom
snehabandla:split/azure-policy-digit-subscripts
Oct 27, 2026
Merged

Anand Krishnamoorthi (anakrish) merged 3 commits into
microsoft:mainfrom
snehabandla:split/azure-policy-digit-subscripts

Conversation

@snehabandla

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #866 (quoted path keys). Tightens how unquoted bracket subscripts are parsed in Azure Policy field paths:

  • Only all-ASCII-digit subscripts index. u64 parsing accepted a leading +, so a[+1] silently became index 1; it is now the key "+1".
  • Overflowing digits stay indexes. config[18446744073709551616] used to fall back to the object key "18446744073709551616". It now saturates to u64::MAX: out of range on any array and never an object key, so the field is Undefined. The quoted form is still a key.
  • Tests pin the remaining edge cases: empty quoted keys error, lone quotes stay literal, leading zeros still index, bracket whitespace is trimmed, dotted numeric segments are keys (properties.ipRules.1.value no longer indexes the array), and quoted numeric keys work through the existenceCondition lookup path.

Testing

Each fix has a counterexample case that fails before it, plus a non-match twin. Validated with Rust 1.95.0: cargo fmt --check, clippy (--all-targets --all-features and --no-default-features), cargo test --all-features --lib azure_policy, cargo test --all-features --test mod azure_policy. Deep-reviewed (round 4, no findings).

Dependencies: none (based on main).

snehabandla and others added 3 commits October 27, 2026 19:52
u64 parsing accepted a leading '+', so a[+1] silently became index 1.
Pin the remaining splitter edge cases: empty quoted keys error, lone
quotes stay literal keys, leading zeros still index, and bracket
whitespace is trimmed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…n keys

Dotted numeric segments are keys, so properties.ipRules.1.value no
longer indexes the array (previously audited). Also run quoted numeric
keys through the existenceCondition lookup path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A bare all-digit subscript that does not fit in u64, such as
properties.config[18446744073709551616], fell back to an object key and
read config["18446744073709551616"], contradicting the rule that only
quoted subscripts are keys. Saturate it to u64::MAX instead: the index
is out of range on any array and never matches an object key, so the
field is Undefined. The quoted form is still a key.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

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.

🟢 Approval recommended

No active review issues require changes to the Azure Policy field-path parsing update.

No open issues 🎉

What changed in this PR

Tightens Azure Policy field-path parsing, building on #866’s distinction between object keys and array indexes.

Changes:

  • Treats only unquoted ASCII-digit bracket subscripts as indexes; signed subscripts remain keys.
  • Saturates overflowing numeric indexes to u64::MAX instead of interpreting them as object keys.
  • Adds regression tests for parser edge cases, dotted numeric segments on arrays, and quoted numeric keys in existence conditions.
File Description
tests/​azure_policy/​cases/​fields.yaml Adds policy-level regression cases for overflow, dotted numeric segments, and existence-condition lookups.
src/​languages/​azure_policy/​compiler/​utils.rs Tightens index classification, saturates overflow, and adds parser unit tests.

Review effort: Balanced

@anakrish
Anand Krishnamoorthi (anakrish) merged commit 6d5c26c into microsoft:main Oct 27, 2026
60 checks passed
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.

3 participants