Repository navigation
Commit fafdaa1
Fix stack overflow and precision loss in toFloatList() conversion (#2451)
toFloatList()'s AGTV_FLOAT branch formatted each element with
sprintf(buffer, "%f", ...) into a fixed 64-byte stack buffer and then
re-parsed the string back into a float. This had two defects:
1. Stack overflow. "%f" prints the full integer part with no width
limit, so a large magnitude overflows the 64-byte buffer. The value
is query-reachable: RETURN toFloatList([1.0e308]) needs ~317 bytes
(309 integer digits + ".000000") and smashes the stack. This is the
issue reported in #2410.
2. Precision loss. "%f" emits only 6 fractional digits, so the
format-and-reparse round trip was lossy -- toFloatList([0.123456789])
returned 0.123457.
The element is already a float8, so the whole format/reparse step is
unnecessary. Assign elem->val.float_value directly. This removes the
stack buffer entirely (no magic buffer size to justify) and fixes both
the overflow and the precision loss at once.
Also harden toStringList(): its "%.*g"/"%ld" conversions use bounded
formats and were never overflow-prone, but switch them from sprintf to
snprintf as defensive depth.
Add regression coverage to regress/sql/expr.sql for both the large
magnitude case (no overflow) and precision preservation.
This reimplements the fix originally proposed by David Christensen in
#2410, whose report identified the sprintf overflow.
Co-authored-by: David Christensen <david.christensen@snowflake.com>1 parent 5137671 commit fafdaa1
3 files changed
Lines changed: 41 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3548 | 3548 | | |
3549 | 3549 | | |
3550 | 3550 | | |
| 3551 | + | |
| 3552 | + | |
| 3553 | + | |
| 3554 | + | |
| 3555 | + | |
| 3556 | + | |
| 3557 | + | |
| 3558 | + | |
| 3559 | + | |
| 3560 | + | |
| 3561 | + | |
| 3562 | + | |
| 3563 | + | |
| 3564 | + | |
| 3565 | + | |
| 3566 | + | |
| 3567 | + | |
| 3568 | + | |
| 3569 | + | |
| 3570 | + | |
3551 | 3571 | | |
3552 | 3572 | | |
3553 | 3573 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1520 | 1520 | | |
1521 | 1521 | | |
1522 | 1522 | | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
| 1531 | + | |
| 1532 | + | |
1523 | 1533 | | |
1524 | 1534 | | |
1525 | 1535 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7099 | 7099 | | |
7100 | 7100 | | |
7101 | 7101 | | |
7102 | | - | |
7103 | | - | |
7104 | 7102 | | |
7105 | 7103 | | |
7106 | 7104 | | |
| |||
7160 | 7158 | | |
7161 | 7159 | | |
7162 | 7160 | | |
| 7161 | + | |
| 7162 | + | |
| 7163 | + | |
| 7164 | + | |
| 7165 | + | |
| 7166 | + | |
| 7167 | + | |
| 7168 | + | |
7163 | 7169 | | |
7164 | | - | |
7165 | | - | |
7166 | | - | |
7167 | | - | |
| 7170 | + | |
7168 | 7171 | | |
7169 | 7172 | | |
7170 | 7173 | | |
| |||
8146 | 8149 | | |
8147 | 8150 | | |
8148 | 8151 | | |
8149 | | - | |
| 8152 | + | |
8150 | 8153 | | |
8151 | 8154 | | |
8152 | 8155 | | |
| |||
8157 | 8160 | | |
8158 | 8161 | | |
8159 | 8162 | | |
8160 | | - | |
| 8163 | + | |
8161 | 8164 | | |
8162 | 8165 | | |
8163 | 8166 | | |
| |||
0 commit comments