Commit b43a417
authored
### Rationale for this change
`Decimal{32,64,128,256}::FromString` parse the exponent as `int32_t`, so a string like `0E-2147483648` reaches `DecimalFromString`/`SimpleDecimalFromString` with `dec.exponent == INT32_MIN` and negating it is UB:
```
decimal.cc: runtime error: negation of -2147483648 cannot be represented in type 'int32_t' (aka 'int')
```
A near-`INT32_MIN` exponent overflows the `-exponent + fractional_digits` addition the same way. Both helpers are reachable from the CSV/JSON readers parsing decimal columns.
### What changes are included in this PR?
Compute the scale via `internal::SubtractWithOverflow` and reject the unrepresentable exponents with `Status::Invalid`, in both helpers.
### Are these changes tested?
Yes, `0E-2147483648` and `1.0E-2147483647` added to `DecimalFromStringTest.InvalidInput` (runs for Decimal32/64/128/256).
### Are there any user-facing changes?
No.
* GitHub Issue: #50057
Lead-authored-by: metsw24-max <metsw24@gmail.com>
Co-authored-by: Sayed Kaif <metsw24@gmail.com>
Signed-off-by: Antoine Pitrou <antoine@python.org>
1 parent 12b3eda commit b43a417
2 files changed
Lines changed: 16 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
881 | 881 | | |
882 | 882 | | |
883 | 883 | | |
884 | | - | |
885 | | - | |
886 | | - | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
887 | 891 | | |
888 | 892 | | |
889 | 893 | | |
| |||
945 | 949 | | |
946 | 950 | | |
947 | 951 | | |
948 | | - | |
949 | | - | |
950 | | - | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
951 | 959 | | |
952 | 960 | | |
953 | 961 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
138 | | - | |
139 | | - | |
| 138 | + | |
| 139 | + | |
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
| |||
0 commit comments