xgbtxy opened a new pull request, #1678: URL: https://github.com/apache/arrow-go/pull/1678
### Rationale for this change `variant.ParseJSON`, `variant.ParseJSONBytes`, and `variant.Unmarshal` panic on valid JSON numbers that have 39 significant digits while still fitting in signed 128-bit integer storage — for example: - `100000000000000000000000000000000000000` (`10^38`) - `170141183460469231731687303715884105727` (`2^127 - 1`) - `-170141183460469231731687303715884105727` - `1.00000000000000000000000000000000000000` (`prec=39, scale=38`) In `(*Builder).tryParseDecimal`, `decimal.PrecScaleFromString` returns `prec = 39` and `scale <= 38`, which passes the scale and 127-bit length checks in `decimal128.FromString` and then panics inside `FitsInPrecision(39)` with `runtime error: index out of range [39] with length 39` (or `precision must be <= 38` under `-tags assert`). Per the Parquet Variant specification, `decimal16` requires `1 <= precision <= 38` and `0 <= scale <= precision`; numbers exceeding those bounds should fall back to `float64` (`Double`), matching how `ParseJSON` already handles larger numbers and scientific notation. ### What changes are included in this PR? - Guard `prec < 1 || prec > decimal128.MaxPrecision || scale < 0 || scale > prec` in `(*Builder).tryParseDecimal` (`parquet/variant/builder.go`) before calling `decimal.Decimal128FromString` and `AppendDecimal16`. - Add `TestParseJSONDecimalPrecisionBounds` in `parquet/variant/builder_test.go` covering the 38-digit `Decimal16` boundary (preserved as exact `Decimal16`) and the 39-digit cases that previously panicked (now parsed as `Double`). ### Are these changes tested? Yes. Confirmed `TestParseJSONDecimalPrecisionBounds` panics before the fix (`index out of range [39] with length 39` / `precision must be <= 38` with `-tags assert`) and passes after the fix under: - `go test -race -count=1 -tags "assert,test" ./parquet/variant/...` - `go test -count=1 -tags "noasm,assert,test" ./parquet/variant/...` - `go vet ./parquet/variant/...` and `gofmt -l` ### Are there any user-facing changes? No breaking API changes; valid JSON numbers exceeding Variant `Decimal16` precision bounds now fall back to `Double` instead of panicking. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
