-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
sql: decimal round can DOS the server #8633
Comments
cc @nvanbenschoten. |
I think we shouldn't allow abnormally large scales in the 2nd argument to round, and it seems to me that negative scales are meaningless. WDYT? |
Wow, yeah the second argument is the number of decimals, definitely needs to be non-negative. As for large values, I think the operation should be a no-op if the number we are rounding already has less decimals than we want. If adding such a check is easy, I think it's the way to go because we don't need to set a hard limit specifically for |
Postgres' behavior when the 2nd arg is higher than the number of decimals is to append 0s:
Notably, though, postgres limits the number of digits after the decimal point to 2000. I'm not sure if that's just with round or with their decimal implementation in general. Upon investigation, this is caused (in cockroach) by the Exp method in decimal. We can easily reproduce this with:
Which similarly pegs a core. That query in postgres says:
But I can't find in the source where that error is coming from to see what they do there. |
FYI the code in pg resides in |
The above query will peg one CPU core at 100% for many minutes until it completes (I have not run it long enough to see how long that is). This is because the implementation of decimal rounding does some quotient remainder calculations that take a while or something.
In any case it's not obvious to me how to handle this, but something should be done since this makes it trivial to shut down a server.
Found with RSG.
The text was updated successfully, but these errors were encountered: