mirror of
https://github.com/postgres/postgres.git
synced 2025-07-09 22:41:56 +03:00
Fix possible internal overflow in numeric multiplication.
mul_var() postpones propagating carries until it risks overflow in its
internal digit array. However, the logic failed to account for the
possibility of overflow in the carry propagation step, allowing wrong
results to be generated in corner cases. We must slightly reduce the
when-to-propagate-carries threshold to avoid that.
Discovered and fixed by Dean Rasheed, with small adjustments by me.
This has been wrong since commit d72f6c7503
,
so back-patch to all supported branches.
This commit is contained in:
@ -1333,6 +1333,33 @@ SELECT * FROM num_input_test;
|
||||
NaN
|
||||
(7 rows)
|
||||
|
||||
--
|
||||
-- Test some corner cases for multiplication
|
||||
--
|
||||
select 4790999999999999999999999999999999999999999999999999999999999999999999999999999999999999 * 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999;
|
||||
?column?
|
||||
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
47909999999999999999999999999999999999999999999999999999999999999999999999999999999999985209000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||
(1 row)
|
||||
|
||||
select 4789999999999999999999999999999999999999999999999999999999999999999999999999999999999999 * 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999;
|
||||
?column?
|
||||
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
47899999999999999999999999999999999999999999999999999999999999999999999999999999999999985210000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||
(1 row)
|
||||
|
||||
select 4770999999999999999999999999999999999999999999999999999999999999999999999999999999999999 * 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999;
|
||||
?column?
|
||||
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
47709999999999999999999999999999999999999999999999999999999999999999999999999999999999985229000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||
(1 row)
|
||||
|
||||
select 4769999999999999999999999999999999999999999999999999999999999999999999999999999999999999 * 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999;
|
||||
?column?
|
||||
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
47699999999999999999999999999999999999999999999999999999999999999999999999999999999999985230000000000000000000000000000000000000000000000000000000000000000000000000000000000001
|
||||
(1 row)
|
||||
|
||||
--
|
||||
-- Test some corner cases for division
|
||||
--
|
||||
|
@ -821,6 +821,18 @@ INSERT INTO num_input_test(n1) VALUES (' N aN ');
|
||||
|
||||
SELECT * FROM num_input_test;
|
||||
|
||||
--
|
||||
-- Test some corner cases for multiplication
|
||||
--
|
||||
|
||||
select 4790999999999999999999999999999999999999999999999999999999999999999999999999999999999999 * 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999;
|
||||
|
||||
select 4789999999999999999999999999999999999999999999999999999999999999999999999999999999999999 * 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999;
|
||||
|
||||
select 4770999999999999999999999999999999999999999999999999999999999999999999999999999999999999 * 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999;
|
||||
|
||||
select 4769999999999999999999999999999999999999999999999999999999999999999999999999999999999999 * 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999;
|
||||
|
||||
--
|
||||
-- Test some corner cases for division
|
||||
--
|
||||
|
Reference in New Issue
Block a user