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

Legacy files: potential issue when falling back on serving directories

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.8.2
    • Fix Version/s: 2.7.6, 2.8.4
    • Component/s: Files API
    • Labels:
    • Testing Instructions:
      Hide

      (difficulty: easy, requires administrator access)

      1. Enable legacy files support;
      2. Create a course where legacy files are enabled;
      3. Go to My courses > Category_Name > Course_Name > Legacy course files and create a mini-site with a folder named 'test' and an HTML file under it named 'index.htm', containing e.g. <html><body><p>It works.</p></body></html>;
      4. Try to point that folder via 'file.php' and expect the HTML file above to be served: access the Legacy course files, browse into 'test' and click on 'index.htm' than take note of the URL e.g. http://hostname/path/to/moodle/file.php/NNN/test/index.htm and point your browser to http://hostname/path/to/moodle/file.php/NNN/test: the index file should appear as well;
      5. Do the same test above but using the HTTP GET file param and w/o the slash arguments e.g. http://hostname/path/to/moodle/file.php?file=/NNN/test/index.htm and http://hostname/path/to/moodle/file.php?file=/NNN/test.
      Show
      (difficulty: easy, requires administrator access) Enable legacy files support; Create a course where legacy files are enabled; Go to My courses > Category_Name > Course_Name > Legacy course files and create a mini-site with a folder named 'test' and an HTML file under it named 'index.htm', containing e.g. <html><body><p>It works.</p></body></html> ; Try to point that folder via 'file.php' and expect the HTML file above to be served: access the Legacy course files , browse into 'test' and click on 'index.htm' than take note of the URL e.g. http://hostname/path/to/moodle/file.php/NNN/test/index.htm and point your browser to http://hostname/path/to/moodle/file.php/NNN/test : the index file should appear as well; Do the same test above but using the HTTP GET file param and w/o the slash arguments e.g. http://hostname/path/to/moodle/file.php?file=/NNN/test/index.htm and http://hostname/path/to/moodle/file.php?file=/NNN/test .
    • Affected Branches:
      MOODLE_28_STABLE
    • Fixed Branches:
      MOODLE_27_STABLE, MOODLE_28_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      m29_MDL-48799_Incorrect_Legacy_Dir_Fallback

      Description

      While trying to understand the reasons behind an issue from the Community (IT: https://moodle.org/mod/forum/discuss.php?d=277907) I've found a minor - IMHO rare - issue on trying to fallback to serve legacy directories: the code will add a trailing "/" but when computing the pathnamehash it re-adds the trailing slash:

      if (!$file = $fs->get_file_by_hash(sha1($fullpath))) {
          if (strrpos($fullpath, '/') !== strlen($fullpath) -1 ) {
              $fullpath .= '/';
          }
          if (!$file = $fs->get_file_by_hash(sha1($fullpath.'/.'))) {
              send_file_not_found();
          }
      }
      

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                9/Mar/15