pgsql: Guard against bad "dscale" values in numeric_recv().

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Guard against bad "dscale" values in numeric_recv().
Дата
Msg-id E1XvXXE-00011n-IO@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
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.

Branch
------
REL9_3_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/10b81fbdc56aecb07c7cfaa1a70da8c1ad70b37d

Modified Files
--------------
src/backend/utils/adt/numeric.c |   15 +++++++++++++++
1 file changed, 15 insertions(+)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: pgsql: Guard against bad "dscale" values in numeric_recv().
Следующее
От: Tom Lane
Дата:
Сообщение: pgsql: Guard against bad "dscale" values in numeric_recv().