pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: tlock.chijin@gmail.com
Subject: BUG #16457: Implicit signed integer truncation or sign change at sortsupport.c:60
Date: Sun, 24 May 2020 15:43:03 +0000
Message-ID: <16457-d00725d27f0d4864@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      16457
Logged by:          ChiJin Zhou
Email address:      tlock.chijin@gmail.com
PostgreSQL version: 12.3
Operating system:   ubuntu 18.04
Description:        

REPRODUCTION && ERROR MESSAGE:

compile the postgres project with UndefinedBehaviorSanitizer and start a
start a server with "postgress" (command: "./postgres -Ddata -p23333"), and
Ubsan reported an error message:
sortsupport.c:60:9: runtime error: implicit conversion from type 'Datum'
(aka 'unsigned long') of value 18446744073709551615 (64-bit, unsigned) to
type 'int' changed the value to -1 (32-bit, signed) 
    #0 0xf3828d in comparison_shim
/root/chijin_workshop/postgres-new/postgres_source_enhanced/src/backend/utils/sort/sortsupport.c:60:9
                                                                       
    #1 0x20a2793 in ApplySortComparator.5353
/root/chijin_workshop/postgres-new/postgres_source_enhanced/src/backend/commands/../../../src/include/utils/sortsupport.h:224:13
                                  
    #2 0x20a1c49 in compare_scalars
/root/chijin_workshop/postgres-new/postgres_source_enhanced/src/backend/commands/analyze.c:2711:12
                                                                         
    #3 0xa9a6bb in med3.26971
/root/chijin_workshop/postgres-new/postgres_source_enhanced/src/port/qsort_arg.c:108:4
                                                                            
              
    #4 0xa98d65 in qsort_arg
/root/chijin_workshop/postgres-new/postgres_source_enhanced/src/port/qsort_arg.c:158:9
                                                                            
               
    #5 0x2094869 in compute_scalar_stats
/root/chijin_workshop/postgres-new/postgres_source_enhanced/src/backend/commands/analyze.c:2284:3
                                                                     
    #6 0x2062fb6 in do_analyze_rel
/root/chijin_workshop/postgres-new/postgres_source_enhanced/src/backend/commands/analyze.c:541:4
                                                                           

    #7 0x2053891 in analyze_rel
/root/chijin_workshop/postgres-new/postgres_source_enhanced/src/backend/commands/analyze.c:260:3
                                                                            
  
    #8 0x204be25 in vacuum
/root/chijin_workshop/postgres-new/postgres_source_enhanced/src/backend/commands/vacuum.c:413:5

SUMMARY: UndefinedBehaviorSanitizer:
implicit-signed-integer-truncation-or-sign-change sortsupport.c:60:9

ROOT CAUSE CODE

The root cause code and explanations are shown bellow (sortsupport.c:60). 

static int
comparison_shim(Datum x, Datum y, SortSupport ssup)
{
        SortShimExtra *extra = (SortShimExtra *) ssup->ssup_extra;
        Datum           result;

        extra->fcinfo.args[0].value = x;
        extra->fcinfo.args[1].value = y;

        /* just for paranoia's sake, we reset isnull each time */
        extra->fcinfo.isnull = false;

        result = FunctionCallInvoke(&extra->fcinfo);                   
<---------- the result value is usigned 64 bit

        /* Check for null result, since caller is clearly not expecting one
*/
        if (extra->fcinfo.isnull)
                elog(ERROR, "function %u returned NULL",
extra->flinfo.fn_oid);

        return result;                   <----------- the return value is
signed 32 bit
}



Message-ID: <16457-d00725d27f0d4864@postgresql.org>
Permalink:  ../16457-d00725d27f0d4864@postgresql.org/
Also on:    postgresql.org/message-id/16457-d00725d27f0d4864@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, tlock.chijin@gmail.com
  Subject: Re: BUG #16457: Implicit signed integer truncation or sign change at sortsupport.c:60
  In-Reply-To: <16457-d00725d27f0d4864@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox