pgsql: Fix possible internal overflow in numeric multiplication. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Fix possible internal overflow in numeric multiplication.
Date
Msg-id E1Ze3iS-0005aG-KG@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
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.

Branch
------
REL9_5_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/3dfffac701cf95e3d9b86f12a3875f9b1b531231

Modified Files
--------------
src/backend/utils/adt/numeric.c       |   14 ++++++++++----
src/test/regress/expected/numeric.out |   27 +++++++++++++++++++++++++++
src/test/regress/sql/numeric.sql      |   12 ++++++++++++
3 files changed, 49 insertions(+), 4 deletions(-)


pgsql-committers by date:

Previous
From: Noah Misch
Date:
Subject: Re: pgsql: Restrict file mode creation mask during tmpfile().
Next
From: Tom Lane
Date:
Subject: pgsql: Fix possible internal overflow in numeric multiplication.