Skip to content

fix: prevent overflow when parsing extreme decimal exponents - #128

Open
pcbeingused333 wants to merge 1 commit into
questdb:mainfrom
pcbeingused333:fix/decimal-exponent-limits
Open

pcbeingused333 wants to merge 1 commit into
questdb:mainfrom
pcbeingused333:fix/decimal-exponent-limits

Conversation

@pcbeingused333

Copy link
Copy Markdown

Fixes #126

Decimal exponent arithmetic could overflow before precision and scale checks, allowing an extreme exponent to reach the powers-of-ten table and throw ArrayIndexOutOfBoundsException instead of NumericException.

Keep the intermediate exponent, virtual scale, digit-drop count and precision calculations in long arithmetic. Validate the natural scale and final precision before narrowing values for the decimal representation. Exponents remain parsed as integers, preserving the accepted input syntax.

Testing and validation

Added the issue's regression test for 1e2147483647, -1e2147483647, 1e-2147483648 and 1.5e-2147483647 across Decimal64, Decimal128 and Decimal256. The regression fails on main with an out-of-bounds index of 2147483647 and passes with this change.

mvn -f core/pom.xml -Dtest=DecimalExponentLimitsTest,Decimal64Test,Decimal128Test,Decimal256Test,DecimalsTest test passes all 459 tests using Maven with Temurin 17. Java 8 execution was not performed.

This change was prepared with assistance from OpenAI Codex.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decimal text with an exponent near the int limits throws ArrayIndexOutOfBoundsException

1 participant