Commit 099beea
authored
fix: fix precision loss for large decimal values (#4135)
* fix(parser): prevent precision loss for numbers > 17 chars
Add length-based bailout to parseFloat() to fix accumulated rounding
errors from repeated *10 operations. For numbers longer than 17
characters, delegate to Number.parseFloat() which handles precision
correctly.
This fixes two critical issues:
- DECIMAL(36,18) precision loss where 50000.000...0 parsed as 49999.999
- MAX_VALUE doubles corruption where last digits were incorrect
The threshold of 17 is based on IEEE 754 double precision limits
(~15-17 significant digits). Testing shows this affects only ~1% of
typical MySQL data while preserving the fast path for 98%+ of cases.
Add comprehensive test suite with 54 test cases covering both issues,
edge cases, and regression tests.
Closes #3690
Closes #2928
* test: add integration tests for issues #3690 and #2928
Add tests exercising parseFloat bailout paths to improve coverage:
- DECIMAL(36,18) with many fractional digits (>17 chars)
- DOUBLE with scientific notation values
These integration tests ensure the bailout conditions are covered
in real database query scenarios.1 parent ff8ed8a commit 099beea
File tree
3 files changed
+380
-6
lines changed- lib/packets
- test
- integration/connection
- unit/packets
3 files changed
+380
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
660 | 660 | | |
661 | 661 | | |
662 | 662 | | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
663 | 679 | | |
664 | 680 | | |
665 | 681 | | |
666 | 682 | | |
667 | 683 | | |
668 | | - | |
669 | | - | |
670 | | - | |
671 | 684 | | |
672 | 685 | | |
673 | 686 | | |
| |||
681 | 694 | | |
682 | 695 | | |
683 | 696 | | |
684 | | - | |
685 | | - | |
686 | | - | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
687 | 704 | | |
688 | 705 | | |
689 | 706 | | |
| |||
Lines changed: 27 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
45 | 72 | | |
46 | 73 | | |
47 | 74 | | |
0 commit comments