Repository navigation
fix: Size decimal string buffers by the value rather than the type's precision - #546
Merged
CurtHagenlocher merged 3 commits intoDec 5, 2026
Merged
Conversation
…precision Formatting a decimal as a string, and parsing one from a string, sized their buffers by the type's precision and scale, and on .NET Core put them on the stack. A type with a very large precision or scale could therefore exhaust the stack. Size the buffers by the digits the value can have instead: a value of a given byte width has at most 2.5 digits per byte, plus the zeros the scale adds. Buffers of up to 256 chars stay on the stack; larger ones go on the heap. Results are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012dFdcrBz22tRjiyNwBd7VB
There was a problem hiding this comment.
🟡 Changes recommended
The parsing tests leave the heap-allocation path and buffer-length overflow guard untested, requiring boundary, extreme-scale, and overflow cases across all four byte widths.
1 open issue
What changed in this PR
This PR reduces stack-exhaustion risk when formatting and parsing Arrow decimals with very large precision or scale.
Changes:
- Sizes buffers from value capacity or input length rather than declared precision.
- Keeps small buffers on the stack and allocates larger buffers on the heap.
- Adds regression tests for huge precision, large formatting scales, and byte-width limits.
| File | Description |
|---|---|
| test/Apache.Arrow.Tests/DecimalUtilityTests.cs | Adds extreme-precision and formatting regression tests. |
| src/Apache.Arrow/DecimalUtility.cs | Revises buffer sizing, allocation thresholds, and overflow checks. |
Review effort: Balanced
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012dFdcrBz22tRjiyNwBd7VB
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012dFdcrBz22tRjiyNwBd7VB
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.


What's changed?
Formatting a decimal as a string (
GetString, and soToStringon 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 precision is still used to reject values with too many digits, and results are unchanged.
Testing
New tests in
DecimalUtilityTestsformat and parse values with a precision of up toint.MaxValueand 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 ofApache.Arrow.Testspasses on net8.0, net462 and net472.🤖 Generated with Claude Code
https://claude.ai/code/session_012dFdcrBz22tRjiyNwBd7VB