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

panic: Type checker panics on ref to object with composite keys #2648

Closed
tsandall opened this issue Aug 21, 2020 · 0 comments
Closed

panic: Type checker panics on ref to object with composite keys #2648

tsandall opened this issue Aug 21, 2020 · 0 comments
Assignees
Labels

Comments

@tsandall
Copy link
Member

This was caught during the nightly fuzzing job. To reproduce:

$ docker run --rm -it openpolicyagent/opa:0.23.1
> x = {{}: {}}; x[1]
panic: unreachable

goroutine 1 [running]:
github.com/open-policy-agent/opa/types.TypeOf(0xbbf880, 0xc000487fb0, 0x1, 0x1)
        /go/src/github.com/open-policy-agent/opa/types/types.go:838 +0x5fc
github.com/open-policy-agent/opa/types.Keys(0xdef460, 0xc00000d160, 0xc00022a2c8, 0x409e8b)
        /go/src/github.com/open-policy-agent/opa/types/types.go:723 +0x131
github.com/open-policy-agent/opa/ast.(*refChecker).checkRefLeaf(0xc00013e810, 0xdef460, 0xc00000d160, 0xc000488e80, 0x2, 0x2, 0x1, 0xc00000d1a0)
        /go/src/github.com/open-policy-agent/opa/ast/check.go:648 +0x83
github.com/open-policy-agent/opa/ast.(*refChecker).checkRef(0xc00013e810, 0xc000489080, 0xc000487f20, 0xc000488e80, 0x2, 0x2, 0x0, 0x0)
        /go/src/github.com/open-policy-agent/opa/ast/check.go:591 +0x12a
github.com/open-policy-agent/opa/ast.(*refChecker).Visit(0xc00013e810, 0xc96600, 0xc00000cc00, 0x90)
        /go/src/github.com/open-policy-agent/opa/ast/check.go:548 +0x428
github.com/open-policy-agent/opa/ast.(*GenericVisitor).Walk(0xc00022a830, 0xc96600, 0xc00000cc00)
        /go/src/github.com/open-policy-agent/opa/ast/visit.go:270 +0x5b
github.com/open-policy-agent/opa/ast.(*GenericVisitor).Walk(0xc00022a830, 0xc6d700, 0xc00000cc20)
        /go/src/github.com/open-policy-agent/opa/ast/visit.go:332 +0xc0d
github.com/open-policy-agent/opa/ast.(*refChecker).Visit(0xc00013e810, 0xc9cbc0, 0xc00045c1e0, 0x203000)
        /go/src/github.com/open-policy-agent/opa/ast/check.go:540 +0x228
github.com/open-policy-agent/opa/ast.(*GenericVisitor).Walk(0xc00022aa68, 0xc9cbc0, 0xc00045c1e0)
        /go/src/github.com/open-policy-agent/opa/ast/visit.go:270 +0x5b
github.com/open-policy-agent/opa/ast.(*typeChecker).CheckBody.func1(0xc00045c1e0, 0x7f58172e3001)
@tsandall tsandall added the bug label Aug 21, 2020
@tsandall tsandall self-assigned this Aug 21, 2020
@tsandall tsandall added this to TODO (Things That Should Be Done) in Open Policy Agent via automation Aug 21, 2020
@tsandall tsandall moved this from TODO (Things That Should Be Done) to In Progress in Open Policy Agent Aug 21, 2020
tsandall added a commit to tsandall/opa that referenced this issue Aug 25, 2020
The type checker was panicing when given a reference to an object with
a composite key because internally it infers the key type using
ast.ValueToInterface (which returns map[string]interface{} and not
map[interface{}]interface{}). This change updates the types package to
support map[string]interface{} internally.

Fixing the TypeOf function resolved the panic but it surfaced another
issue in the type checker where errors were returned if objects or
arrays were dereferenced with composite keys--in case of arrays, the
result is undefined but in the case of objects, this is valid.

Fixes open-policy-agent#2648

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
Open Policy Agent automation moved this from In Progress to Done Aug 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

No branches or pull requests

1 participant