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

Using modulo with floating points causes panic #1245

Closed
jaspervdj opened this issue Mar 4, 2019 · 1 comment
Closed

Using modulo with floating points causes panic #1245

jaspervdj opened this issue Mar 4, 2019 · 1 comment
Labels

Comments

@jaspervdj
Copy link
Contributor

Expected Behavior

I would expect that using floating points with the modulo operator is caught somewhere and an error is raised. This is similar to what happens if you e.g. divide by zero:

jasper@kakigori$ opa run
OPA 0.10.5 (commit 8b08af7f, built at 2019-02-25T16:39:16Z)

Run 'help' to see a list of commands.

> 1 / 0
1 / 0: eval_internal_error: div: divide by zero
> 

Actual Behavior

The process panics:

jasper@kakigori$ opa run
OPA 0.10.5 (commit 8b08af7f, built at 2019-02-25T16:39:16Z)

Run 'help' to see a list of commands.

> 1.1 % 1
panic: illegal value

goroutine 1 [running]:
github.com/open-policy-agent/opa/topdown/builtins.NumberToInt(0xc000203850, 0x3, 0xd6e360)
        /go/src/github.com/open-policy-agent/opa/topdown/builtins/builtins.go:163 +0x96
...
main.main()
        /go/src/github.com/open-policy-agent/opa/main.go:12 +0x2d

Steps to Reproduce the Problem

  1. Start opa run
  2. Enter e.g. 1.1 % 1

Additional Info

  • OPA version 0.10.5
  • Linux 4.20.13 on x86_64
@tsandall tsandall added the bug label Mar 4, 2019
@tsandall
Copy link
Member

tsandall commented Mar 4, 2019

@jaspervdj thanks for the excellent bug report.

I think we can update the built-in function to check the operand types and do integer modulo floating-point modulo accordingly.

That check ought to happen here: https://github.com/open-policy-agent/opa/blob/master/topdown/arithmetic.go#L126

ashutosh-narkar added a commit to ashutosh-narkar/opa that referenced this issue Mar 8, 2019
Fixes open-policy-agent#1245

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
ashutosh-narkar added a commit that referenced this issue Mar 8, 2019
Fixes #1245

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants