forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit26f8a46
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 parent030fd8a commit26f8a46
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 | |
---|---|---|---|
| |||
5440 | 5440 |
| |
5441 | 5441 |
| |
5442 | 5442 |
| |
| 5443 | + | |
5443 | 5444 |
| |
5444 | 5445 |
| |
5445 | 5446 |
| |
5446 | 5447 |
| |
| 5448 | + | |
5447 | 5449 |
| |
5448 | 5450 |
| |
5449 | 5451 |
| |
| |||
5477 | 5479 |
| |
5478 | 5480 |
| |
5479 | 5481 |
| |
5480 |
| - | |
| 5482 | + | |
5481 | 5483 |
| |
5482 | 5484 |
| |
5483 | 5485 |
| |
5484 | 5486 |
| |
5485 | 5487 |
| |
5486 | 5488 |
| |
5487 |
| - | |
| 5489 | + | |
5488 | 5490 |
| |
5489 | 5491 |
| |
5490 | 5492 |
| |
5491 | 5493 |
| |
5492 |
| - | |
| 5494 | + | |
5493 | 5495 |
| |
5494 | 5496 |
| |
5495 |
| - | |
| 5497 | + | |
5496 | 5498 |
| |
| 5499 | + | |
| 5500 | + | |
| 5501 | + | |
| 5502 | + | |
| 5503 | + | |
| 5504 | + | |
| 5505 | + | |
| 5506 | + | |
| 5507 | + | |
| 5508 | + | |
| 5509 | + | |
| 5510 | + | |
| 5511 | + | |
| 5512 | + | |
| 5513 | + | |
| 5514 | + | |
| 5515 | + | |
| 5516 | + | |
| 5517 | + | |
| 5518 | + | |
5497 | 5519 |
| |
5498 | 5520 |
| |
5499 | 5521 |
| |
|
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)