forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitb0e9e4d
committed
Avoid overflow in width_bucket_float8().
The original coding of this function paid little attention to thepossibility of overflow. There were actually three different hazards:1. The range from bound1 to bound2 could exceed DBL_MAX, which onIEEE-compliant machines produces +Infinity in the subtraction.At best we'd lose all precision in the result, and at worstproduce NaN due to dividing Inf/Inf. The range can't exceedtwice DBL_MAX though, so we can fix this case by scaling all theinputs by 0.5.2. We computed count * (operand - bound1), which is also at risk offloat overflow, before dividing. Safer is to do the division first,producing a quotient that should be in [0,1), and even after allowingfor roundoff error can't be outside [0,1]; then multiplying by countcan't produce a result overflowing an int. (width_bucket_numeric doesthe multiplication first on the grounds that that improves accuracy ofits result, but I don't think that a similar argument can be made infloat arithmetic.)3. If the division result does round to 1, and count is INT_MAX,the final addition of 1 would overflow an int. We took careof that in the operand >= bound2 case but did not consider thatit could be possible in the main path. Fix that by moving theoverflow-aware addition of 1 so it is done that way in all cases.The fix for point 2 creates a possibility that values very close toa bucket boundary will be rounded differently than they were before.I'm not troubled by that for HEAD, but it is an argument againstputting this into the stable branches. Given that the cases beingfixed here are fairly extreme and unlikely to be hit in normal use,it seems best not to back-patch.Mats Kindahl and Tom LaneDiscussion:https://postgr.es/m/17876-61f280d1601f978d@postgresql.org1 parent2fe7a6d commitb0e9e4d
File tree
3 files changed
+89
-15
lines changed- src
- backend/utils/adt
- test/regress
- expected
- sql
3 files changed
+89
-15
lines changedLines changed: 28 additions & 15 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
4090 | 4090 |
| |
4091 | 4091 |
| |
4092 | 4092 |
| |
4093 |
| - | |
| 4093 | + | |
4094 | 4094 |
| |
4095 | 4095 |
| |
4096 | 4096 |
| |
| |||
4108 | 4108 |
| |
4109 | 4109 |
| |
4110 | 4110 |
| |
| 4111 | + | |
4111 | 4112 |
| |
4112 |
| - | |
| 4113 | + | |
4113 | 4114 |
| |
| 4115 | + | |
| 4116 | + | |
4114 | 4117 |
| |
4115 |
| - | |
4116 |
| - | |
4117 |
| - | |
4118 |
| - | |
| 4118 | + | |
| 4119 | + | |
4119 | 4120 |
| |
4120 | 4121 |
| |
4121 |
| - | |
| 4122 | + | |
| 4123 | + | |
| 4124 | + | |
| 4125 | + | |
| 4126 | + | |
| 4127 | + | |
| 4128 | + | |
| 4129 | + | |
| 4130 | + | |
| 4131 | + | |
| 4132 | + | |
4122 | 4133 |
| |
4123 | 4134 |
| |
4124 | 4135 |
| |
4125 | 4136 |
| |
4126 |
| - | |
| 4137 | + | |
4127 | 4138 |
| |
4128 |
| - | |
4129 |
| - | |
4130 |
| - | |
4131 |
| - | |
4132 |
| - | |
4133 |
| - | |
| 4139 | + | |
| 4140 | + | |
| 4141 | + | |
4134 | 4142 |
| |
4135 |
| - | |
| 4143 | + | |
4136 | 4144 |
| |
4137 | 4145 |
| |
4138 | 4146 |
| |
| |||
4142 | 4150 |
| |
4143 | 4151 |
| |
4144 | 4152 |
| |
| 4153 | + | |
| 4154 | + | |
| 4155 | + | |
| 4156 | + | |
| 4157 | + | |
4145 | 4158 |
| |
4146 | 4159 |
|
Lines changed: 39 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1473 | 1473 |
| |
1474 | 1474 |
| |
1475 | 1475 |
| |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + | |
| 1487 | + | |
| 1488 | + | |
| 1489 | + | |
| 1490 | + | |
| 1491 | + | |
| 1492 | + | |
| 1493 | + | |
| 1494 | + | |
| 1495 | + | |
| 1496 | + | |
| 1497 | + | |
| 1498 | + | |
| 1499 | + | |
| 1500 | + | |
| 1501 | + | |
| 1502 | + | |
| 1503 | + | |
| 1504 | + | |
| 1505 | + | |
| 1506 | + | |
| 1507 | + | |
| 1508 | + | |
| 1509 | + | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
| 1514 | + | |
1476 | 1515 |
| |
1477 | 1516 |
| |
1478 | 1517 |
| |
|
Lines changed: 22 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
910 | 910 |
| |
911 | 911 |
| |
912 | 912 |
| |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
913 | 935 |
| |
914 | 936 |
| |
915 | 937 |
| |
|
0 commit comments
Comments
(0)