• Tom Lane's avatar
    Guard against bad "dscale" values in numeric_recv(). · 0927bf80
    Tom Lane authored
    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.
    0927bf80
numeric.c 157 KB