forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit228ed43
committed
Fix power_var_int() for large integer exponents.
The code for raising a NUMERIC value to an integer power wasn't verycareful about large powers. It got an outright wrong answer for anexponent of INT_MIN, due to failure to consider overflow of the Abs(exp)operation; which is fixable by using an unsigned rather than signedexponent value after that point. Also, even though the number ofiterations of the power-computation loop is pretty limited, it's easy forthe repeated squarings to result in ridiculously enormous intermediatevalues, which can take unreasonable amounts of time/memory to process,or even overflow the internal "weight" field and so produce a wrong answer.We can forestall misbehaviors of that sort by bailing out as soon as theweight value exceeds what will fit in int16, since then the final answermust overflow (if exp > 0) or underflow (if exp < 0) the packed numericformat.Per off-list report from Pavel Stehule. Back-patch to all supportedbranches.1 parent7679eff commit228ed43
File tree
3 files changed
+54
-4
lines changed- src
- backend/utils/adt
- test/regress
- expected
- sql
3 files changed
+54
-4
lines changedLines changed: 26 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
5696 | 5696 |
| |
5697 | 5697 |
| |
5698 | 5698 |
| |
| 5699 | + | |
5699 | 5700 |
| |
5700 | 5701 |
| |
5701 | 5702 |
| |
5702 | 5703 |
| |
| 5704 | + | |
5703 | 5705 |
| |
5704 | 5706 |
| |
5705 | 5707 |
| |
| |||
5733 | 5735 |
| |
5734 | 5736 |
| |
5735 | 5737 |
| |
5736 |
| - | |
| 5738 | + | |
5737 | 5739 |
| |
5738 | 5740 |
| |
5739 | 5741 |
| |
5740 | 5742 |
| |
5741 | 5743 |
| |
5742 | 5744 |
| |
5743 |
| - | |
| 5745 | + | |
5744 | 5746 |
| |
5745 | 5747 |
| |
5746 | 5748 |
| |
5747 | 5749 |
| |
5748 |
| - | |
| 5750 | + | |
5749 | 5751 |
| |
5750 | 5752 |
| |
5751 |
| - | |
| 5753 | + | |
5752 | 5754 |
| |
| 5755 | + | |
| 5756 | + | |
| 5757 | + | |
| 5758 | + | |
| 5759 | + | |
| 5760 | + | |
| 5761 | + | |
| 5762 | + | |
| 5763 | + | |
| 5764 | + | |
| 5765 | + | |
| 5766 | + | |
| 5767 | + | |
| 5768 | + | |
| 5769 | + | |
| 5770 | + | |
| 5771 | + | |
| 5772 | + | |
| 5773 | + | |
| 5774 | + | |
5753 | 5775 |
| |
5754 | 5776 |
| |
5755 | 5777 |
| |
|
Lines changed: 19 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1390 | 1390 |
| |
1391 | 1391 |
| |
1392 | 1392 |
| |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + |
Lines changed: 9 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
828 | 828 |
| |
829 | 829 |
| |
830 | 830 |
| |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + |
0 commit comments
Comments
(0)