Skip to content

fix: Size decimal string buffers by the value rather than the type's precision (#546) - #548

Merged
CurtHagenlocher merged 1 commit into
apache:maint-23.xfrom
CurtHagenlocher:decimal-format-precision-23.x
Dec 5, 2026
Merged

CurtHagenlocher merged 1 commit into
apache:maint-23.xfrom
CurtHagenlocher:decimal-format-precision-23.x

Conversation

@CurtHagenlocher

Copy link
Copy Markdown
Contributor

Brings #546 to maint-23.x. It applied cleanly.

…precision (apache#546)

### What's changed?

Formatting a decimal as a string (`GetString`, and so `ToString` on the
decimal arrays) and parsing one from a string sized their buffers by the
type's precision and scale. On .NET Core the buffers were on the stack,
so a type with a very large precision or scale could exhaust it.

- The buffers are now sized by the digits the value can have. A value of
a given byte width has at most 2.5 digits per byte, plus any zeros the
scale adds.
- Buffers of up to 256 chars stay on the stack; larger ones go on the
heap. Sizes are computed so they can't overflow.
- On .NET Framework the buffers were already on the heap, but were sized
by the precision; they are now sized the same way.

The precision is still used to reject values with too many digits, and
results are unchanged.

### Testing

New tests in `DecimalUtilityTests` format and parse values with a
precision of up to `int.MaxValue` and a scale of 1,000,000, at byte
widths 4, 8, 16 and 32, and format the largest and smallest value of
each width with a very large precision. All of `Apache.Arrow.Tests`
passes on net8.0, net462 and net472.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_012dFdcrBz22tRjiyNwBd7VB

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 266791f)
@CurtHagenlocher
CurtHagenlocher merged commit b4aea39 into apache:maint-23.x Dec 5, 2026
14 checks passed
@CurtHagenlocher
CurtHagenlocher deleted the decimal-format-precision-23.x branch December 5, 2026 15:09
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.

1 participant