Lstarsky0 commented on issue #10789:
URL: https://github.com/apache/arrow-rs/issues/10789#issuecomment-5383881365
This and #10790 are the same line.
`parse_e_notation` ends its validation with
```rust
if digits == 0 && fractionals == 0 && exp == 0 {
return Err(...);
}
```
`exp == 0` is standing in for "the mantissa was empty", and it is neither
necessary nor sufficient:
- `"0e0"` *has* a mantissa, but `parse_decimal`'s digit arm does `if digits
== 0 && *b == b'0' { continue; }`, so a literal zero never increments `digits`.
All three terms are zero and the guard fires. That is this issue.
- `"e5"` has *no* mantissa, but `exp` is 5, so the guard does not fire. That
is #10790.
Measured on `main` with `parse_decimal::<Decimal128Type>(input, 10, 2)`:
```
"0e0" -> Err(can't parse the string value 0e0 to decimal)
"0E0" -> Err
"-0e0" -> Err
"0e1" -> Ok(0)
"e5" -> Ok(0)
"E5" -> Ok(0)
"1e0" -> Ok(100)
```
`"0e1"` is the one that shows it cleanly: identical to `"0e0"` in every way
that should matter, accepted only because the exponent digit happens to be
non-zero.
For completeness on #10790's other example, `"-"` is already rejected — but
by the check at the top of `parse_decimal`, which only inspects `bs.last()`.
That is also why `"e5"` gets as far as it does: its last byte is a digit, so
the early gate passes it through.
So the fix is one flag rather than two patches: track "saw at least one
mantissa digit" separately from the significant-digit count, and gate on that
instead of on `digits == 0 && fractionals == 0 && exp == 0`. `digits` cannot
answer the question it is being asked here, because the leading-zero `continue`
is what makes it a count of *significant* digits in the first place.
--
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]