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

mem_root_dynamic_array_resize_and_set_val does not allow to set values for fixed-size dynamic arrays

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • None
    • None
    • None
    • None

    Description

      The functions mem_root_dynamic_array_resize_and_set_val (include/my_sys.h) starts with following code:

      static inline int mem_root_dynamic_array_resize_and_set_val(MEM_ROOT_DYNAMIC_ARRAY *array,
                                         const void *element, size_t idx)
      {
        if (array->malloc_flags & MY_BUFFER_NO_RESIZE)
          return TRUE;
       
        if (idx >= array->max_element)
        {
          if (mem_root_allocate_dynamic(array->mem_root, array, idx))
            return 1;
          array->elements++;
        }
      ...
      

      The very first two lines returns TRUE (failure) when array is of fixed size.

      In the Columnstore we have to use dynamic arrays with fixed size buffers when calling json_normalize. The normalization process then calls mem_root_dynamic_array_resize_and_set_val and this function with valid index and value arguments and it fails to set the value. The incorrect (unset) value then read by other parts of program resulting in crash.

      A better code variant would be like this:

      static inline int mem_root_dynamic_array_resize_and_set_val(MEM_ROOT_DYNAMIC_ARRAY *array,
                                         const void *element, size_t idx)
      {
        if (idx >= array->max_element)
        {
          if (array->malloc_flags & MY_BUFFER_NO_RESIZE)
            return TRUE;
       
          if (mem_root_allocate_dynamic(array->mem_root, array, idx))
            return 1;
          array->elements++;
        }
      ...
      

      Here we fail only when index is too big. This particular code change allows Columnstore to use json_normalize function without problems.

      Attachments

        Issue Links

          Activity

            People

              rucha174 Rucha Deodhar
              sergey.zefirov Sergey Zefirov
              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.