Don't count leading zeros toward parse :max_digits#232
Merged
Conversation
Inspect renders 34-digit coefficients with negative exponents in the [-6, 0] adjusted range using fixed-point form, prepending "0." (e.g. "0.3162277660168379331998893544432719"). The leading zero pushed the parsed digit count one past the default precision of 34, so the inspect output failed to round-trip through Decimal.parse/Decimal.new. Check the parsed coefficient's significant digit count instead, matching what decimal_within_limits?/2 already does for non-string casts. Closes #231
The previous commit moved the :max_digits check past digits_acc_to_integer, so adversarial inputs like "9" * 1_000_000 spent ~260ms building the coefficient before being rejected. The CVE-2026-32686 mitigation specifically relied on rejecting at parse_digits_count to avoid that materialization. Track leading zeros while parsing (and skip accumulating them), then check total_size - leading_zeros against :max_digits before constructing the coefficient. Restores the parse-time bound for digit-rich inputs and keeps the list size bounded by significant digits for leading-zero inputs, while preserving the round-trip fix.
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.
Inspect renders 34-digit coefficients with negative exponents in the [-6, 0] adjusted range using fixed-point form, prepending "0." (e.g. "0.3162277660168379331998893544432719"). The leading zero pushed the parsed digit count one past the default precision of 34, so the inspect output failed to round-trip through Decimal.parse/Decimal.new.
Check the parsed coefficient's significant digit count instead, matching what decimal_within_limits?/2 already does for non-string casts.
Closes #231