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

Encoding based error in class "stored_file_exporter", method "get_other_values"

XMLWordPrintable

      An issue has been identified in the forum grading process, and it may potentially occur elsewhere as well.

      Tested on:

      • Moodle 4.1.6+ (Build: 20231116)
      • Moodle 4.2.3+ (Build: 20231116)
      • Moodle 4.3+ (Build: 20231116)

      PHP versions:

      • PHP 8.0.30
      • PHP 8.1.24

      Steps to reproduce:
      1) Create a graded forum.
      2) A student uploads an attached file named "Мазитов А.З. практика тусур.py".
      3) When a teacher attempts to assign a grade, an "invalidresponse" error occurs.

      Upon further investigation, the following issues were identified:
      1) The AJAX function "mod_forum_get_discussion_posts_by_userid" does not return a response.
      2) During the service call, a JSON serialization error occurs with the code "JSON_ERROR_UTF8" = "Malformed UTF-8 characters, possibly incorrectly encoded".
      3) After examining the service response dump before serialization, it was observed that in the "attachments" array of objects, the field "filenameshort" takes the value "Мазитов А.З. пра..�.py" (corrupted value).
      4) Further analysis of the code led to the class "core_files\external\stored_file_exporter", specifically the method "get_other_values", where the "substr()" function is used incorrectly to truncate the file name.

      Solution:
      Replace the "substr()" calls with "core_text::substr()".

      Code:

      Before:

      if (core_text::strlen($filename) > 25) {
          $filenameshort = shorten_text(substr($filename, 0, -4), 21, true, '..');
          $filenameshort .= substr($filename, -4);
      }

      After:

      if (core_text::strlen($filename) > 25) {
          $filenameshort = shorten_text(core_text::substr($filename, 0, -4), 21, true, '..');
          $filenameshort .= core_text::substr($filename, -4);
      }

            pholden Paul Holden
            mazart Artem
            Andrew Lyons Andrew Lyons
            Jun Pataleta Jun Pataleta
            CiBoT CiBoT
            Votes:
            0 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 46 minutes
                46m

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