Details

    • Type: Sub-task Sub-task
    • Status: Closed
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: 2.3
    • Fix Version/s: 2.3
    • Component/s: Filepicker, Files API
    • Labels:
    • Affected Branches:
      MOODLE_23_STABLE
    • Fixed Branches:
      MOODLE_23_STABLE
    • Rank:
      39994

      Description

      While working on the thumbnails support, I encountered this very weird bug and can't cope with it. Here are steps to reproduce it at my laptop:

      1. Prepare a checkout of Marina's branch https://github.com/marinaglancy/moodle/compare/master...wip-MDL-31901-master
      2. Apply the following trivial patch:

      diff --git a/lib/filelib.php b/lib/filelib.php
      index 9fcca04..cc24924 100644
      --- a/lib/filelib.php
      +++ b/lib/filelib.php
      @@ -600,6 +600,12 @@ function file_get_drafarea_files($draftitemid, $filepath = '/') {
                       // do NOT use file browser here!
                       $item->url = moodle_url::make_draftfile_url($draftitemid, $item->filepath, $item->filename)->out();
                       $item->thumbnail = $OUTPUT->pix_url(file_extension_icon($item->filename, 32))->out(false);
      +                if ($imageinfo = $file->get_imageinfo()) {
      +                    $item->thumbnail = $item->url;
      +                    $item->icon = $item->url;
      +                }
                   }
                   $list[] = $item;
               }
      

      As you can see, all the patch does is that it forces to use the full-sized image as the icon and the thumbnail.
      3. Create a Folder resource instance.
      4. Edit the folder contents and upload a single image to it.
      5. TEST: The image is used as the 90x90 "thumbnail" (not real thumbnail as it loads the full image but that does not matter now)
      6. Click "View as list" button

      Expected behavior: the image resized to 16x16 "thumbnail" is displayed next to the filename and I can save the Folder contents

      What actually happens: Just after clicking the button, the session is terminated and you are logged out!

      Analysis: somehow, loading draftfile.php from the list view terminates the session. The weird thing is that the 90x90 "thumbnail" image is correctly loaded at the first page via the very same URL and then it does not cases session terminus (in other words, unless you click the "View as list" button, you can safely work with the files).

        Issue Links

          Activity

          Hide
          David Mudrak added a comment -

          Adding Petr as the watcher in case he spots something. This is driving me crazy for a couple of hours now. It might be something trivial or even some local issue. Any feedback welcome. Thanks mates.

          Show
          David Mudrak added a comment - Adding Petr as the watcher in case he spots something. This is driving me crazy for a couple of hours now. It might be something trivial or even some local issue. Any feedback welcome. Thanks mates.
          Hide
          David Mudrak added a comment -

          Hmm, note that draftfile.php is probably not a problem here - if you manually copy the image's URL like http://glum/~mudrd8mz/moodle23/draftfile.php?file=%2F5%2Fuser%2Fdraft%2F389146029%2Ffreemind.png you can download it as many times as you want in another tab/windows and the session is not terminated.

          Crazy.

          Show
          David Mudrak added a comment - Hmm, note that draftfile.php is probably not a problem here - if you manually copy the image's URL like http://glum/~mudrd8mz/moodle23/draftfile.php?file=%2F5%2Fuser%2Fdraft%2F389146029%2Ffreemind.png you can download it as many times as you want in another tab/windows and the session is not terminated. Crazy.
          Hide
          Marina Glancy added a comment - - edited

          Hi David, there is nothing crazy here.

          First, there is nothing to do with particular view mode, the error repeats itself in icon view mode and table view mode if you navigate through folders, just list view mode has several requests, one for each folder.

          Second, session is not terminated. There is a notice produced by getimagesize() that results in unparsable string.
          Notice: getimagesize(): Read error! in .../lib/filestorage/stored_file.php on line 282

          If you set the debug level higher there'll be no errors in filemananger.

          Regarding the notice there are actually two-and-a-half issues here:
          1. in stored_file::get_imageinfo() the content is not recovered if unreadable. Look at other functions that request content in the stored_file.php like get_content() and get_content_file_handle()

          2. function getimagesize() when applied to non-image files always produces the 'read error' notice.

          3. something I found in http://php.net/manual/en/function.getimagesize.php - that if filesize is 0, this notice is also produced.

          I guess, function stored_file::get_imageinfo() was not actually used before. This is my fix to it
          https://github.com/marinaglancy/moodle/commit/ede30964134cd40d0a8908198ed3dc39e0c5895c

          Show
          Marina Glancy added a comment - - edited Hi David, there is nothing crazy here. First, there is nothing to do with particular view mode, the error repeats itself in icon view mode and table view mode if you navigate through folders, just list view mode has several requests, one for each folder. Second, session is not terminated. There is a notice produced by getimagesize() that results in unparsable string. Notice: getimagesize(): Read error! in .../lib/filestorage/stored_file.php on line 282 If you set the debug level higher there'll be no errors in filemananger. Regarding the notice there are actually two-and-a-half issues here: 1. in stored_ file::get_imageinfo( ) the content is not recovered if unreadable. Look at other functions that request content in the stored_file.php like get_content() and get_content_file_handle() 2. function getimagesize() when applied to non-image files always produces the 'read error' notice. 3. something I found in http://php.net/manual/en/function.getimagesize.php - that if filesize is 0, this notice is also produced. I guess, function stored_ file::get_imageinfo( ) was not actually used before. This is my fix to it https://github.com/marinaglancy/moodle/commit/ede30964134cd40d0a8908198ed3dc39e0c5895c
          Hide
          Marina Glancy added a comment -

          honestly, looking at stored_file class, the content recovery should be part of function stored_file::get_content_file_location() and there would be no need for code duplication.

          Petr, what do you think?

          Show
          Marina Glancy added a comment - honestly, looking at stored_file class, the content recovery should be part of function stored_ file::get_content_file_location( ) and there would be no need for code duplication. Petr, what do you think?
          Hide
          David Mudrak added a comment -

          Marina, thanks for considering this. However, our observations differ. In my case, my session IS terminated for some reason (Petr saw that) and I do not get any notices nor errors (and yes, of course I have debugging enabled).

          Show
          David Mudrak added a comment - Marina, thanks for considering this. However, our observations differ. In my case, my session IS terminated for some reason (Petr saw that) and I do not get any notices nor errors (and yes, of course I have debugging enabled).
          Hide
          David Mudrak added a comment -

          Thanks Petr for testing this, too. Petr was not able to reproduce this. I just tried in another browser and it works ok there. So I am getting session termination in Firefox/Vimperator, but my Chrome works well. Weird. But at least, it seems to be a local issue. I am tempted to close this as "Not a bug". Just wondering if other users would experience this one day.

          Show
          David Mudrak added a comment - Thanks Petr for testing this, too. Petr was not able to reproduce this. I just tried in another browser and it works ok there. So I am getting session termination in Firefox/Vimperator, but my Chrome works well. Weird. But at least, it seems to be a local issue. I am tempted to close this as "Not a bug". Just wondering if other users would experience this one day.
          Hide
          David Mudrak added a comment -

          I just created https://github.com/marinaglancy/moodle/pull/2 to merge thumbnails support into the filemanager.

          Show
          David Mudrak added a comment - I just created https://github.com/marinaglancy/moodle/pull/2 to merge thumbnails support into the filemanager.
          Hide
          Marina Glancy added a comment -

          David, this hangs on my list with alarming priority. What shall we do with it?
          I actually already have one commit with this issue number in it (fixing getimagesize), so don't just close it please.

          Are you still able to reproduce it? Why do you think that session is terminated, could it be a wrong error message?

          Show
          Marina Glancy added a comment - David, this hangs on my list with alarming priority. What shall we do with it? I actually already have one commit with this issue number in it (fixing getimagesize), so don't just close it please. Are you still able to reproduce it? Why do you think that session is terminated, could it be a wrong error message?
          Hide
          David Mudrak added a comment -

          From the HQ chat:

          (14:06:54) Davo Smith: I had a similar problem with course drag and drop in firefox
          (14:07:23) Davo Smith: it seemed to be related to URLs with '~' in them ending up with '%7e' instead
          (14:07:40) Davo Smith: (via the AJAX / JSON response)
          (14:08:32) Davo Smith: the only solution I found was to call:
          div.innerHTML = unescape(div.innerHTML); (within 'if Y.UA.gecko > 0')

          In my case, I have URL with ~ too - like http://localhost/~mudrd8mz/moodle23/

          Show
          David Mudrak added a comment - From the HQ chat: (14:06:54) Davo Smith: I had a similar problem with course drag and drop in firefox (14:07:23) Davo Smith: it seemed to be related to URLs with '~' in them ending up with '%7e' instead (14:07:40) Davo Smith: (via the AJAX / JSON response) (14:08:32) Davo Smith: the only solution I found was to call: div.innerHTML = unescape(div.innerHTML); (within 'if Y.UA.gecko > 0') In my case, I have URL with ~ too - like http://localhost/~mudrd8mz/moodle23/
          Hide
          Petr Škoda added a comment - - edited

          oh!! "~" is known to cause other problems too, it is NOT recommended and is definitely not tested - my +2 to add admin page warning for it...
          this is the same for any fancy characters the need to be encoded in URLs

          Safe chars for $CFG->wwwroot dirs are [a-z0-9_\-] only.

          Show
          Petr Škoda added a comment - - edited oh!! "~" is known to cause other problems too, it is NOT recommended and is definitely not tested - my +2 to add admin page warning for it... this is the same for any fancy characters the need to be encoded in URLs Safe chars for $CFG->wwwroot dirs are [a-z0-9_\-] only.
          Hide
          David Mudrak added a comment -

          Yay! I can confirm this is caused by the ~ character in the $CFG->wwwroot. After removing it, the problem disappears and everything works in Firefox, too.

          Show
          David Mudrak added a comment - Yay! I can confirm this is caused by the ~ character in the $CFG->wwwroot. After removing it, the problem disappears and everything works in Firefox, too.
          Hide
          Marina Glancy added a comment -

          yay, great!

          Show
          Marina Glancy added a comment - yay, great!

            People

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

              Dates

              • Created:
                Updated:
                Resolved: