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

For some binary files add_string_to_pool wrongly evaluates filesize when strlen() is overloaded (mbstring.func_overload)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Do
    • Icon: Major Major
    • None
    • 3.1.1, 3.1.2
    • Files API
    • MOODLE_31_STABLE

      Hi

      add_string_to_pool for check write correct file rests on strlen function, but strlen calculate size of string before read \0 symbol. In this case length of strlen and length of file_put_contents may be differs with actual length write by file_put_contents.

      In my case: I can't import questions with images, because moodle crash when tries create image.
      Call stack: line 2080 of /lib/filestorage/file_storage.php: file_exception thrown
      line 1587 of /lib/filestorage/file_storage.php: call to file_storage->add_string_to_pool()
      line 239 of /question/format/xml/format.php: call to file_storage->create_file_from_string()
      line 597 of /question/format/xml/format.php: call to qformat_xml->import_headers()
      line 973 of /question/format/xml/format.php: call to qformat_xml->import_shortanswer()
      line 951 of /question/format/xml/format.php: call to qformat_xml->import_question()
      line 939 of /question/format/xml/format.php: call to qformat_xml->import_questions()
      line 304 of /question/format.php: call to qformat_xml->readquestions()
      line 123 of /question/import.php: call to qformat_default->importprocess()

      Some lines can have offset, because I add debug print messages.

      Additional info:

      Some variables:
      $filerecord: Array ( [contextid] => 1866 [component] => user [filearea] => draft [itemid] => 77325933 [filepath] => / [filename] => Images_forQuizQuestions_STP_ОсновыCSharpNET1.png )
      $hashfile: /var/www/moodledata/filedir/90/11/901107dc30615f5afdfc7f2a6f7ae003a1681b18
      $hashfile333: /var/www/moodledata/filedir/90/11/901107dc30615f5afdfc7f2a6f7ae003a1681b18
      $hashfile333b: /var/www/moodledata/filedir/90/11/901107dc30615f5afdfc7f2a6f7ae003a1681b18
      $newsize: 8790
      $filesize: 6787
      strlen($content): 6787
      $hashfile555: /var/www/moodledata/filedir/90/11/901107dc30615f5afdfc7f2a6f7ae003a1681b18

      In this print variables you can see different sizes in $newsize from file_put_contents have more value than $filesize and strlen($content). For check that of length is correct, I extract base64 conent from XML and place this in one line on new file. Text editor show me 11720 symbols from begin. Than I calculate to standard byte: (11720*6)/8=8790. It's equal with length factual wrote by file_put_contents function.

      My version moodle is 3.1.1+ 20160908b

      I attach file with questions.

      Thanks,
      Artem Matveev

        1. STP_Test1_Previe1.1.xml
          162 kB
          Artem Matveev
        2. screenshot-2.png
          180 kB
          Artem Matveev
        3. screenshot-3.png
          123 kB
          Artem Matveev
        4. screenshot-4.png
          86 kB
          Artem Matveev
        5. screenshot-5.png
          59 kB
          Artem Matveev

            matteo Matteo Scaramuccia
            21a1ss3 Artem Matveev
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

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