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

The JSON mutators always blame argument 1 in a diagnostic and report a position inside an internal buffer

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Minor
    • Resolution: Unresolved
    • 10.11, 11.4, 11.8, 12.3, 13.0
    • None
    • JSON
    • None

    Description

      When a mutator fails part-way, the diagnostic it raises names argument 1
      and gives a position, whatever argument actually caused the failure and
      however short argument 1 is.

      SET @d31 = CONCAT(REPEAT('[', 31), '1', REPEAT(']', 31));
      SELECT JSON_INSERT('[1]', '$[1]', JSON_COMPACT(@d31)) AS v;
      v
      NULL
      Warnings:
      Warning  4040  Limit of 32 on JSON nested structures depth is
                     reached in argument 1 to function 'json_insert'
                     at position 35

      Argument 1 is the three-byte literal `[1]`. It is a valid document, it
      has no position 35, and it is not what exceeded the depth limit -
      argument 3 is.

      How to repeat

      SET @d31 = CONCAT(REPEAT('[', 31), '1', REPEAT(']', 31));
      SELECT JSON_INSERT('[1]', '$[1]', JSON_COMPACT(@d31))        AS v;
      SELECT JSON_SET('{"a":1}', '$.b', JSON_COMPACT(@d31))        AS v;
      SELECT JSON_REPLACE('{"a":1}', '$.a', JSON_COMPACT(@d31))    AS v;
      SELECT JSON_ARRAY_APPEND('[1]', '$', JSON_COMPACT(@d31))     AS v;
      -- each names argument 1 at a position argument 1 does not have

      Root cause

      Every mutator's error path reports against the buffer the function has
      been composing rather than against the argument that failed, and passes
      a literal zero as the argument index. The reporting helper then adds
      one to that index and computes the position as an offset into the buffer
      it was handed, so the message is always "argument 1" at an offset into
      something the caller never wrote.

      Note

      This rests on the message being a false statement about a named
      argument, which is measurable, and not on any documented sentence about
      which argument a diagnostic should name.

      Affected versions

      The mutators were added in 10.2.3 and have reported this way
      throughout.

      Verified on 10.11 only (10.11.19-MariaDB-debug, commit 1dab253482d).
      Other branches were not tested.

      Note

      Found while auditing the JSON functions against their documented
      contracts. Pinned as recorded output in five or more places -
      func_json_depth.result:139/144/149/154/298/312 all record a warning
      naming argument 1 at a position that argument does not have.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              arcivanov Arcadiy Ivanov
              Votes:
              0 Vote for this issue
              Watchers:
              1 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.