Fix possible internal overflow in numeric multiplication.
authorTom Lane
Mon, 21 Sep 2015 16:11:32 +0000 (12:11 -0400)
committerTom Lane
Mon, 21 Sep 2015 16:11:49 +0000 (12:11 -0400)
commitfa9fc3a1b8069c0ab5edcd6f8b0caf679fed9392
treea856ed7cb5ac207a7eced8c9bfeb5a19918ef994
parent7496aba8085a21f8296f19b2e8f07e9723f946a5
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 d72f6c75038d8d37e64a29a04b911f728044d83b,
so back-patch to all supported branches.
src/backend/utils/adt/numeric.c
src/test/regress/expected/numeric.out
src/test/regress/sql/numeric.sql