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:45 +0000 (12:11 -0400)
commit3dfffac701cf95e3d9b86f12a3875f9b1b531231
tree3e885bf7ae31bdbb3563c8d81dbab0f782d8a831
parentbbdb9dfbc3c722b4c811c5cbfa03ce79b7b74824
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