[MDEV-23105] Cast number string with many leading zeros to decimal gives unexpected result Created: 2020-07-06 Updated: 2020-10-06 Resolved: 2020-08-06 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Data types |
| Affects Version/s: | 10.1, 10.2, 10.3, 10.4, 10.5 |
| Fix Version/s: | 10.1.48, 10.2.35, 10.3.26, 10.4.16, 10.5.7 |
| Type: | Bug | Priority: | Major |
| Reporter: | Sergey Lebedev | Assignee: | Alexander Barkov |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Description |
|
Casting numeric representing decimal value string with many leading "SELECT gives value 9999999999999.99 The bug appears when input string is longer than 83 symbols and is It could be dangerous in many case, for for example for online financial |
| Comments |
| Comment by Elena Stepanova [ 2020-08-04 ] | ||||||||||||||||||
|
FWIW, it throws not even one, but two warnings while doing so, on all versions of MariaDB and MySQL (the text can be slightly different between different versions):
If a financial service doesn't pay attention to warnings, it is bound to have dangerous problems. Still, assigning to bar to check if it needs to be fixed. | ||||||||||||||||||
| Comment by Alexander Barkov [ 2020-08-05 ] | ||||||||||||||||||
|
I think it's a bug. It could strip the leading '0' before actual converting to DECIMAL representation. | ||||||||||||||||||
| Comment by Sergey Lebedev [ 2020-08-05 ] | ||||||||||||||||||
|
Thank you for fixing the issue! IMHO the main problem here was that having too long input string it throws number overflow error, not 'Input string is too long' or something like that error. Which leads to a logical bug - too long input string causes wrong output number. And yes - stripping leading zeros in input string is The Right Thing |