Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-80938

File storage field referencefileid converted from null to zero by clean_param()

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 4.1.5
    • Files API
    • MOODLE_401_STABLE

      In \file_storage\create_file_from_storedfile(), there is a clean_param() operation on the file's referencefileid and referencelastsync fields.  This can be seen here:

      https://github.com/moodle/moodle/blob/328b48ebc592a8f0a551aacc6e2e447a50a50c90/lib/filestorage/file_storage.php#L1176

      The problem is that, if the value of either referencefileid or referencelastsync before this operation is null, the operation converts the null value to zero. 

      So the new file record in the database will be incorrect, which can cause problems such as  outlined in a ticket raised on the format_tiles plugin at https://bitbucket.org/dw8/moodle-format_tiles/issues/165/bug-report-issue-with-referencefileid

      A proposed fix to preserve the null value would be to change the problem line as follows:

      Before:

      if ($key == 'referencefileid' or $key == 'referencelastsync') {
          $value = clean_param($value, PARAM_INT);
      }

                 
      After:

      if (($key == 'referencefileid' or $key == 'referencelastsync') && $value !== null) {
          $value = clean_param($value, PARAM_INT);
      } 

      (This original code was added in 2012 under commit 67233725 (MDL-28666)

            dw8 David Watson
            dw8 David Watson
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.