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

Error writing to database when multiple sections inline images

    XMLWordPrintable

    Details

    • Affected Branches:
      MOODLE_24_STABLE, MOODLE_25_STABLE

      Description

      Editing in some browsers (firefox) inline the image when pasting from some sources.

      <img src="data:image/png;base64,iVBORw0KGgoAAAA...." />

      When multiple sections in a course are updated by copying and pasting images into the editor it is possible to get a 'Error writing to database' screen that prevents viewing or editing a course.

      The PHP code execution of the following :-

      UPDATE mdl_course SET modinfo = ?,sectioncache = ? WHERE id=?

      Results in :-

      Error code: dmlwriteexception* line 429 of /lib/dml/moodle_database.php: dml_write_exception thrown

      • line 1213 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
      • line 1245 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->update_record_raw()
      • line 1459 of /lib/modinfolib.php: call to mysqli_native_moodle_database->update_record()
      • line 259 of /lib/modinfolib.php: call to rebuild_course_cache()
      • line 1383 of /lib/modinfolib.php: call to course_modinfo->:onstruct()

      Although each of the sections is below the max_allowed_packet threshold the sectioncache is a composite of all the individual summary entries and this is over the threshold and hence breaks that module in Moodle.

      Steps to reproduce

      1. Open website in Firefox
      2. Login
      3. Select a course
      4. Selected turn editing on
      5. Edit the section you need to update using cogwheel icon beneath section.
      6. Open an image in an image editing application such as GIMP
      7. Copy image from GIMP
      8. Paste image CTRL+V into Summary section
      9. Select the image that was inserted in the Summary editor
      10. Click the insert/edit Image icon (small picture of a tree)
      11. You should see a pop up with a very long image URL starting something like "data:image/png;base64,...." followed by lots of random charecters.
      10. Click Cancel to exit insert/edit image
      11. Click Save changes for the section
      12. Repeat Steps 5 to 11 a number of times (using a 1Mb image 5 times should be enough)
      13. Turn off

      Alternate method without using firefox

      1. From unix promp encode a file using :-
      echo -n 'data:image/png;base64,' > image_file.png.txt; base64 image_file.png | sed ':a;N;$!ba;s/\n//g' >> image_file.png.txt
      2. Login
      3. Select a course
      4. Selected turn editing on
      5. Edit the section you need to update using cogwheel icon beneath section.
      6. Click the insert/edit Image icon (small picture of a tree)
      7. Open image_file.png.txt file in a text editor and copy the contents
      8. Paste into the Image URL box
      9. You should see a pop up with a very long image URL starting something like "data:image/png;base64,...." followed by lots of random charecters.
      10. Click Insert to exit insert/edit image
      11. Click Save changes for the section
      12. Repeat Steps 5 to 11 a number of times (using a 1Mb image 5 times should be enough)
      13. Turn off

      Managed to reproduce on demo.moodle.net where viewing returns a blank mage not the error however limits are probably set to 16Mb so harder to do.

      The following is a valid example of embedding a black line in the src of an image

      <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABAAAAAABCAIAAADPbEtiAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3QsHDBEaL9KP9wAAABlJREFUSMftwQEBAAAAgiD/r25IQAEAADcGDAEAAbeUObEAAAAASUVORK5CYII=" width="1024" height="1" />
      

        Attachments

        1. diff_for_lib_filelib_php.txt
          3 kB
        2. diff_for_lib_modinfolib_php.txt
          2 kB
        3. diff_for_lib_modinfolib_php.txt
          2 kB
        4. filelib.php
          175 kB
        5. filelib.php
          175 kB
        6. modinfolib.php
          66 kB
        7. modinfolib.php
          66 kB

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              undermine Patrick Mulvany
              Participants:
              Component watchers:
              Matteo Scaramuccia, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona), Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona), Andrew Lyons, Dongsheng Cai, Huong Nguyen, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze
              Votes:
              4 Vote for this issue
              Watchers:
              6 Start watching this issue

                Dates

                Created:
                Updated: