Skip to content

Don't count leading zeros toward parse :max_digits#232

Merged
ericmj merged 2 commits into
mainfrom
ericmj/fix-round-trip-leading-zeros
May 9, 2026
Merged

Don't count leading zeros toward parse :max_digits#232
ericmj merged 2 commits into
mainfrom
ericmj/fix-round-trip-leading-zeros

Conversation

@ericmj
Copy link
Copy Markdown
Owner

@ericmj ericmj commented May 9, 2026

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

ericmj added 2 commits May 8, 2026 17:16
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.
@ericmj ericmj merged commit 4c521da into main May 9, 2026
2 checks passed
@austin-nl austin-nl mentioned this pull request May 19, 2026
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.

Decimals don't round trip if the precision is exactly the context size and the exponent is negative

1 participant