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

JSON_ARRAY_APPEND/JSON_REMOVE return invalid (truncated) JSON when materialized in a derived table

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Critical
    • Resolution: Duplicate
    • 13.0.2
    • N/A
    • JSON
    • None
    • Docker
      Server version: 13.0.2-MariaDB-ubu2604
      Source revision: 620a4b5624222048fece7fe1789978ae0675cae2
    • Not for Release Notes

    Description

      Hi, I found a logic bug in MariaDB 13.0.2.

      JSON_ARRAY_APPEND and JSON_REMOVE produce valid JSON when evaluated directly, but the same
      expression materialized through a derived table is truncated to an invalid JSON string
      (18 -> 16 bytes and 21 -> 17 bytes). JSON_EXTRACT, which was fixed by MDEV-38873, is correct
      in the same derived-table form, so only its sibling functions are still affected.

      Expected results:

      +----------------+------------+
      | probe          | json_valid |
      +----------------+------------+
      | append direct  |          1 |
      | append derived |          1 |
      | remove direct  |          1 |
      | remove derived |          1 |
      +----------------+------------+
      

      Actual Results:

      +----------------+------------+
      | probe          | json_valid |
      +----------------+------------+
      | append direct  |          1 |
      | append derived |          0 |
      | remove direct  |          1 |
      | remove derived |          0 |
      +----------------+------------+
      

      The truncated values themselves:

      +--------------------+------+   +------------------+------+
      | direct             | dlen |   | derived          | len  |
      +--------------------+------+   +------------------+------+
      | [1, 1, 1, 1, 1, 1] |   18 |   | [1, 1, 1, 1, 1,  |   16 |
      +--------------------+------+   +------------------+------+
       
      +-----------------------+------+   +-------------------+------+
      | direct                | dlen |   | derived           | len  |
      +-----------------------+------+   +-------------------+------+
      | [1, 1, 1, 1, 1, 1, 1] |   21 |   | [1, 1, 1, 1, 1, 1 |   17 |
      +-----------------------+------+   +-------------------+------+
      

      How to repeat:

      SELECT 'append direct'  AS probe, JSON_VALID(JSON_ARRAY_APPEND('[1,1,1,1,1]','$',1)) AS json_valid
      UNION ALL
      SELECT 'append derived', JSON_VALID(j) FROM (SELECT JSON_ARRAY_APPEND('[1,1,1,1,1]','$',1) AS j) d
      UNION ALL
      SELECT 'remove direct',  JSON_VALID(JSON_REMOVE('[1,1,1,1,1,1,1,1]','$[0]'))
      UNION ALL
      SELECT 'remove derived', JSON_VALID(j) FROM (SELECT JSON_REMOVE('[1,1,1,1,1,1,1,1]','$[0]') AS j) d;
       
      -- the truncation in full
      SELECT JSON_ARRAY_APPEND('[1,1,1,1,1]','$',1) AS direct,
             LENGTH(JSON_ARRAY_APPEND('[1,1,1,1,1]','$',1)) AS dlen;
      SELECT j AS derived, LENGTH(j) AS len
      FROM (SELECT JSON_ARRAY_APPEND('[1,1,1,1,1]','$',1) AS j) d;
      SELECT JSON_REMOVE('[1,1,1,1,1,1,1,1]','$[0]') AS direct,
             LENGTH(JSON_REMOVE('[1,1,1,1,1,1,1,1]','$[0]')) AS dlen;
      SELECT j AS derived, LENGTH(j) AS len
      FROM (SELECT JSON_REMOVE('[1,1,1,1,1,1,1,1]','$[0]') AS j) d;
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              Yuxiao Guo Yuxiao Guo
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

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