• Gleb Shchepa's avatar
    Bug #40761: Assert on sum function on · 423ca289
    Gleb Shchepa authored
                IF(..., CAST(longtext AS UNSIGNED), signed_val)
                (was: LEFT JOIN on inline view crashes server)
    
    Select from a LONGTEXT column wrapped with an expression
    like "IF(..., CAST(longtext_column AS UNSIGNED), smth_signed)"
    failed an assertion or crashed the server. IFNULL function was
    affected too.
    
    LONGTEXT column item has a maximum length of 32^2-1 bytes,
    at the same time this is a maximum possible length of any
    MySQL item. CAST(longtext_column AS UNSIGNED) returns some
    unsigned numeric result of length 32^2-1, so the result of
    IF/IFNULL function of this number and some other signed number
    will have text length of (32^2-1)+1=32^2 (one byte for the
    minus sign) - there is integer overflow, and the length is
    equal to zero. That caused assert/crash.
    
    CAST AS UNSIGNED function has been modified to limit maximal
    length of resulting number to 67 (maximal length of DECIMAL
    and two characters for minus sign and dot).
    
    
    mysql-test/r/func_if.result:
      Added test case for bug #40761.
    mysql-test/t/func_if.test:
      Added test case for bug #40761.
    sql/item_func.h:
      Bug #40761: Assert on sum function on
                  IF(..., CAST(longtext AS UNSIGNED), signed_val)
      
      CAST AS UNSIGNED function has been modified to limit maximal
      length of resulting number to 67 (maximal length of DECIMAL
      and two characters for minus sign and dot).
    423ca289
func_if.test 4.17 KB