postgresql/src
Tom Lane 10b81fbdc5 Guard against bad "dscale" values in numeric_recv().
We were not checking to see if the supplied dscale was valid for the given
digit array when receiving binary-format numeric values.  While dscale can
validly be more than the number of nonzero fractional digits, it shouldn't
be less; that case causes fractional digits to be hidden on display even
though they're there and participate in arithmetic.

Bug #12053 from Tommaso Sala indicates that there's at least one broken
client library out there that sometimes supplies an incorrect dscale value,
leading to strange behavior.  This suggests that simply throwing an error
might not be the best response; it would lead to failures in applications
that might seem to be working fine today.  What seems the least risky fix
is to truncate away any digits that would be hidden by dscale.  This
preserves the existing behavior in terms of what will be printed for the
transmitted value, while preventing subsequent arithmetic from producing
results inconsistent with that.

In passing, throw a specific error for the case of dscale being outside
the range that will fit into a numeric's header.  Before you got "value
overflows numeric format", which is a bit misleading.

Back-patch to all supported branches.
2014-12-01 15:25:08 -05:00
..
backend Guard against bad "dscale" values in numeric_recv(). 2014-12-01 15:25:08 -05:00
bin Make \watch respect the user's \pset null setting. 2014-11-28 02:44:40 +09:00
common Remove tabs after spaces in C comments 2014-05-06 11:26:28 -04:00
include Fix hstore_to_json_loose's detection of valid JSON number values. 2014-12-01 11:44:48 -05:00
interfaces Fix minor bugs in commit 30bf4689a9 et al. 2014-11-30 12:20:51 -05:00
makefiles Don't use deprecated dllwrap on Cygwin. 2014-02-01 16:13:32 -05:00
pl Make plpython_unicode regression test work in more database encodings. 2014-06-03 12:02:13 -04:00
port Fix win32setlocale.c const-related warnings. 2014-11-02 21:44:28 -05:00
template Remove _FORTIFY_SOURCE 2012-10-10 21:42:38 -04:00
test Don't require bleeding-edge timezone data in timestamptz regression test. 2014-11-18 21:36:46 -05:00
timezone Update time zone data files to tzdata release 2014j. 2014-11-17 12:08:25 -05:00
tools MSVC: Substitute $(top_builddir) in REGRESS_OPTS. 2014-07-23 00:35:53 -04:00
tutorial Remove tabs after spaces in C comments 2014-05-06 11:26:28 -04:00
.gitignore Convert cvsignore to gitignore, and add .gitignore for build targets. 2010-09-22 12:57:04 +02:00
bcc32.mak Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
DEVELOPERS Replace a couple of references to files that no longer exist in the source 2009-05-04 08:08:47 +00:00
Makefile Create libpgcommon, and move pg_malloc et al to it 2013-02-12 11:21:05 -03:00
Makefile.global.in Revert "Backpatch pgxs vpath build and installation fixes." 2013-10-07 22:32:04 -04:00
Makefile.shlib fix whitespace 2014-02-01 16:30:22 -05:00
nls-global.mk NLS: Use msgmerge --previous option 2012-12-13 23:12:12 -05:00
win32.mak Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00