forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitcf5c20b
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 parent7288331 commitcf5c20b
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 | |
---|---|---|---|
| |||
5649 | 5649 |
| |
5650 | 5650 |
| |
5651 | 5651 |
| |
| 5652 | + | |
5652 | 5653 |
| |
5653 | 5654 |
| |
5654 | 5655 |
| |
5655 | 5656 |
| |
| 5657 | + | |
5656 | 5658 |
| |
5657 | 5659 |
| |
5658 | 5660 |
| |
| |||
5686 | 5688 |
| |
5687 | 5689 |
| |
5688 | 5690 |
| |
5689 |
| - | |
| 5691 | + | |
5690 | 5692 |
| |
5691 | 5693 |
| |
5692 | 5694 |
| |
5693 | 5695 |
| |
5694 | 5696 |
| |
5695 | 5697 |
| |
5696 |
| - | |
| 5698 | + | |
5697 | 5699 |
| |
5698 | 5700 |
| |
5699 | 5701 |
| |
5700 | 5702 |
| |
5701 |
| - | |
| 5703 | + | |
5702 | 5704 |
| |
5703 | 5705 |
| |
5704 |
| - | |
| 5706 | + | |
5705 | 5707 |
| |
| 5708 | + | |
| 5709 | + | |
| 5710 | + | |
| 5711 | + | |
| 5712 | + | |
| 5713 | + | |
| 5714 | + | |
| 5715 | + | |
| 5716 | + | |
| 5717 | + | |
| 5718 | + | |
| 5719 | + | |
| 5720 | + | |
| 5721 | + | |
| 5722 | + | |
| 5723 | + | |
| 5724 | + | |
| 5725 | + | |
| 5726 | + | |
| 5727 | + | |
5706 | 5728 |
| |
5707 | 5729 |
| |
5708 | 5730 |
| |
|
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)