Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stack overflow when running partial eval on a rule where variable is accidentally repeated #3559

Closed
TheLunaticScripter opened this issue Jun 15, 2021 · 2 comments · Fixed by #3637
Assignees
Labels

Comments

@TheLunaticScripter
Copy link
Contributor

This is the policy that I'm evaluating. I accidentally duplicated a variable and then ran a partial evaluation on the rule. As a result, I got a stack overflow error. Here is my policy

package rule

sql {
  allowed[_]
}
allowed[file] {
  some file
  file = data.file[file]
  file.owner = input.user.name
}

with the following input

{
  "user": {
    "name": "alice"
  }
}

When I run this command

opa eval -p -i input.json -b . data.rules.sql=true --unknowns data.file -f pretty

I get the stack overflow

To fix this I modified either the some file variable or the file = data.file to be something else for example files and it works as expected.

I believe that this is expected behavior in that the file variable should not be declared in more than one place but I would have expected an unsafe rego error.

@srenatus srenatus self-assigned this Jul 12, 2021
@srenatus
Copy link
Contributor

Looking into this 👀

@srenatus
Copy link
Contributor

Note that this may also happen not by accident. A boiled-down version of this would be

package test

p {
  q[_]
}
q[x] {
  x = input[x]
}

where, with input and object, q would be the set of all key/value pairs that match, i.e. input = {"x": "x"} would yield q = { "x" }.

The infinite recursion happens in copy propagation, when running PE in shallow mode, it won't occur.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants