Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-41518

YEAR Field Constant Folding Bypasses Truncation Check in convert_const_to_int

    XMLWordPrintable

Details

    Description

      For YEAR-typed fields, stored_field_cmp_to_item() (which detects
      truncation before folding a string constant into an integer) is only
      called when field->type() == MYSQL_TYPE_LONGLONG, so it is skipped for
      YEAR fields, leaving field_cmp at 0. The truncation check always passes,
      so fractional/ambiguous string constants get silently folded into a
      matching year.

      CREATE TABLE t_year (id INT, y YEAR);
      INSERT INTO t_year VALUES (1, 2000), (2, 1999), (3, 2001), (4, 0000), (5, 2099);
       
      SELECT id, y FROM t_year WHERE y = '00';
      SELECT id, y FROM t_year WHERE y = 2000;
       
      SELECT id, y FROM t_year WHERE y = '2000.9';
       
      DROP TABLE t_year;
      

      SELECT id, y FROM t_year WHERE y = '00';
      id	y
      1	2000
      SELECT id, y FROM t_year WHERE y = 2000;
      id	y
      1	2000
      SELECT id, y FROM t_year WHERE y = '2000.9';
      id	y
      3	2001
      

      Reported by: Yuelin Wang

      Attachments

        Issue Links

          Activity

            People

              bar Alexander Barkov
              alice Alice Sherepa
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.