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

"Download All Submissions" in Assignment doesn't check file name length, resulting in unextractable files


    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Minor Minor
    • None
    • 2.9.3
    • Assignment

      All popular file systems (NTFS, EXT3, HFS) have a limit of 255 characters in file names (including extensions). Moodle itself expects this, because the filename field in the mdl_files is a VARCHAR(255). Trying to rename a file to something longer than this results in "Error writing to database", as you'd expect (although that error perhaps isn't the friendliest way to tell the user their file name is too long).

      However, Moodle's assignment tool has a "Download All Submissions" option, which creates a ZIP file with all the files in. When adding files to the ZIP, this tool adds extra details to the start of the filename, including the student's full name and the assignment's CMID.

      If an assignment submission has a really long file name and it's close to the 255 character limit, prepending this information to the filename will push the file over the 255 character limit, leading to a ZIP file which doesn't meet the ZIP specification and a file in the ZIP that can't be extracted. Windows and OS X's built-in ZIP tools will refuse to extract anything, saying the ZIP file is invalid (Win) or a filename is too long (Mac). The Linux unzip command will extract everything from the ZIP except the problematic file.

      Steps to Reproduce

      • Create an assignment in a Moodle course
      • Upload a submission with a really long file name (roughly 250 characters in length)
      • As a teacher, try to download the file individually from the grading view. The file will download successfully.
      • As a teacher, download all submissions as a ZIP using the link in the assignment administration menu.
      • Try to extract the downloaded ZIP file. Windows gives an error "The compressed folder is invalid". Mac OS X's Archive Extractor gives says "Error 63 - File name too long". Linux's unzip command says "cannot create filename"

      Possible Fixes

      • When creating the assignment ZIP file, check the length of the file name with the data prepended. Truncate as necessary.
      • While we're at it, put a maxlength on the file uploader's renaming popup, so the user doesn't attempt to set a filename longer than the Moodle database can handle, resulting in Error writing to database.

            Unassigned Unassigned
            lexx_koto Alex Walker
            1 Vote for this issue
            2 Start watching this issue


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