Update to Decimal 3.0, update dependencies, fix Elixir 1.19 warnings#67
Conversation
- Update decimal dependency to ~> 3.0 (with backwards compat for ~> 1.5 and ~> 2.0) - Update other dependencies in mix.lock - Move preferred_cli_env to def cli (deprecated in Mix 1.19) - Replace single-quoted charlists with ~c sigil in doctests - Fix compile-time type checker warning in conversion test
|
@danielberkompas There is a moderate vulnerability in the |
Decimal.new/1 in 3.x rejects strings exceeding the default max_digits (28). Use Decimal.parse/2 with max_digits: 100 in the BitString implementation of Number.Conversion.to_decimal/1. Also narrows the decimal dep spec to ~> 3.0 since parse/2 with max_digits is a 3.x-only API. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
|
Problem Decimal 3.x made The crash path: Fix Replace Since |
Problem
Decimal 3.x made
Decimal.new/1strict about the number of significant digits it accepts (default max: 28). This causesNumber.Delimit.number_to_delimited/2andNumber.Currency.number_to_currency/2to crash withDecimal.Errorwhen given float-derived strings with more than 28 significant digits (e.g."0.02053473047423571351409743977530517"— 35 digits, typical of IEEE 754 double-precision float-to-string conversion).The crash path:
number_to_delimitedconverts a non-integer input to a string viato_string/1, then passes it throughNumber.Conversion.to_decimal/1, which callsDecimal.new/1on the raw string.Fix
Replace
Decimal.new(string)withDecimal.parse(string, max_digits: 100)in theBitStringimplementation ofNumber.Conversion.to_decimal/1. This is the single chokepoint where arbitrary strings become Decimals in the library. 100 digits provides generous headroom beyond any realistic float-derived input while still bounding the parse.Since
Decimal.parse/2with themax_digitsoption is a 3.x-only API, this also narrows the decimal dependency to~> 3.0. If backwards compatibility with decimal 1.x/2.x is desired, a compile-time check forfunction_exported?(Decimal, :parse, 2)could be added — happy to make that change if needed.