[CALCITE-7731] Bound plain-notation expansion of DECIMAL literals to prevent parse-time OutOfMemoryError - #5204
[CALCITE-7731] Bound plain-notation expansion of DECIMAL literals to prevent parse-time OutOfMemoryError#5204rubenada wants to merge 3 commits into
Conversation
…prevent parse-time OutOfMemoryError
mihaibudiu
left a comment
There was a problem hiding this comment.
Not easy to tell by eye whether all the places where the conversion happens have been instrumented.
I wonder whether the exception message size is a concern. Is the problem only when the original literal is small but the internal representation is large?
| @Override public String toValue() { | ||
| final BigDecimal bd = getValueNonNull(); | ||
| if (exact) { | ||
| if (!SqlUtil.isBoundedDecimal(bd)) { |
There was a problem hiding this comment.
could this error message be very large too?
There was a problem hiding this comment.
Yes, well spotted. I have changed it into bd.toString() , which should be the less OOM-risky alternative.
The problem is mostly when |
|



Jira Link
CALCITE-7731
Changes Proposed
BigDecimal accepts any int exponent, so a DECIMAL literal such as DECIMAL '1E2147483647' (~12 characters) parses to a BigDecimal whose plain-notation form would be one character per digit: a multi-gigabyte allocation (potentially an OOM error).
Three places call BigDecimal.toPlainString() on a value derived from user-supplied input and would attempt that allocation:
It is required to add a check in there to prevent an OOM error.