Repository navigation
fix: prevent overflow when parsing extreme decimal exponents - #128
Open
pcbeingused333 wants to merge 1 commit into
Open
pcbeingused333 wants to merge 1 commit into
pcbeingused333 wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-2147483648and1.5e-2147483647across 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 testpasses all 459 tests using Maven with Temurin 17. Java 8 execution was not performed.This change was prepared with assistance from OpenAI Codex.