[CALCITE-7750] Bound plain-notation expansion of DECIMAL literals in Primitive.checkOverflow - #5223
[CALCITE-7750] Bound plain-notation expansion of DECIMAL literals in Primitive.checkOverflow#5223shoemoney wants to merge 1 commit into
Conversation
|
The linter won't like your commit message. Have you tried to validate this locally? |
…Primitive.checkOverflow Primitive.checkOverflow calls BigDecimal.toPlainString on a value with scale < 0 without bounding the plain-notation expansion, the same pattern bounded elsewhere in CALCITE-7731. A large negative scale can force toPlainString to materialize gigabytes and OOM. Gate the toPlainString call with isBoundedDecimal, mirroring SqlUtil.isBoundedDecimal in core but inlined in linq4j to avoid a circular linq4j -> core dependency. The bound reads calcite.parser.maxDecimalLiteralPlainDigits (default 10000) and checks precision + abs(scale) <= limit, throwing IllegalArgumentException before allocation if exceeded.
c9a1bd9 to
c9ed2c6
Compare
|
Fixed, commit message now uses [CALCITE-7731] in c9ed2c6. |
|
I have changed your PR title to match |
|
Is this really needed? Can we get into a "risky" scenario here, considering the checks introduced in CALCITE-7731 ? |
|
|
@shoemoney , thanks for the patch. Honestly, I don't know if we can realistically fall into a risky scenario for this class (looks like a "pattern-matching" fix). But the check won't hurt. Also, please add some unit tests for this in PrimitiveTest.java, e.g. one for regression coverage, one reproducing the actual issue: |



Sibling of CALCITE-7731.
Bug: Primitive.checkOverflow calls BigDecimal.toPlainString on a value with scale < 0 without bounding the plain-notation expansion. A large negative scale can force toPlainString to materialize gigabytes and OOM, same pattern bounded elsewhere in CALCITE-7731.
Fix: Gate the toPlainString call with isBoundedDecimal. This mirrors SqlUtil.isBoundedDecimal in core but is inlined in linq4j to avoid a circular linq4j -> core dependency. The bound reads calcite.parser.maxDecimalLiteralPlainDigits (default 10000) and checks precision + abs(scale) <= limit. If exceeded, throw IllegalArgumentException before allocation.
Evidence: RED->GREEN verified. Both :linq4j:compileJava configurations succeed. Formatter blast radius is one file.