owncloud / core

:cloud: ownCloud web server core (Files, DAV, etc.)
https://owncloud.com
GNU Affero General Public License v3.0
8.31k stars 2.06k forks source link

filemtime() and filesize() stat fail when gallery app is used #8051

Closed mmattel closed 10 years ago

mmattel commented 10 years ago

Server configuration

Ubuntu Ubuntu 12.04.4 LTS, 64 bit, latest patches Apache 2.2.22, MySQL 5.5.35, PHP 5.3.10 ownCloud version:ownCloud 7.0 pre alpha (git), master 2014.04.03 (morning)

This is a clean and fresh install. No encryption, external local mountpoints (ubuntu smb share), additional apps enabled: gallery and music

Problem

I have already created an issue in gallery some time ago (https://github.com/owncloud/gallery/issues/19) describing that filetime() stat is failing, but now filesize() stat fails too with the same problem. I could think of that this is not gallery only related but has also roots in core.

There are many error messages in oc log like: filemtime(): stat failed for /mnt/www/owncloud-git/data/xxxxxx/gallery/xxxxxx//picturepathname.tiff at /mnt/www/owncloud-git/apps2/gallery/lib/thumbnail.php#95

It turnes out that the path component has a extra slash This extra slash is ...xxxxxx//picturepathname.tiff.... (two consecutive slashes after the user name) And therefore the file is not accessible and stat returns a error

PVince81 commented 10 years ago

@icewind1991 any idea ?

mmattel commented 10 years ago

I have digged further into the code and found following:

These code files helped to get closer to the problem:

I added some code in my system to backtrace calling routines and/or created log entries in oC to see particular variable content when the routines are called.

(1) https://github.com/owncloud/gallery/blob/master/lib/thumbnail.php#L95 (2) https://github.com/owncloud/core/blob/master/lib/base.php#L781 (3) https://github.com/owncloud/gallery/blob/master/ajax/thumbnail.php#L33

There is more than one problem behind this issue.

1.) There is a foldername present which contains special characters. In this case: /mnt/www/owncloud-git/data/xxxxxxx/gallery/xxxxxxx/Video Mac/ (T)Raumschiff Surprise - Periode 1 - D 2004, Komoedie.eyetv

2.) There is a extra slash added by oC in the path

ad 2.) this can be easy fixed by changing the codeline of (3) from: $image = new \OCA\Gallery\Thumbnail('/' . $img, $user, $square); to $image = new \OCA\Gallery\Thumbnail($img, $user, $square);

ad 1.) there are more things to be done.

a.) In a nutshell, we need to set paths / files in single quotes to eliminate the possibility of struggling over special characters (tested with a small php script with stat and the foldername described above) b.) This must be done on more than one point, the question is where. Calling or called procedure c.) Gallery: It seems that when files are created, first the folder is created and then the file. If the folder contains a special character, the creation of the file fails.

PVince81 commented 10 years ago

I'm not sure I really understand the problem. Which special character do you think was causing the issue ?

If you have an idea how to fix it, feel free to submit a PR. The gallery code is in https://github.com/owncloud/gallery

mmattel commented 10 years ago

I have cleared up things. The reason for the error message is in the log, but I have overseen an important detail. The files caused the trouble originally are from type .tif which is right now not proper processable. I was a bit confused, because when I tried to change manually to the directory which starts with (T)... , I get a error in Ubuntu. This blinded me a bit and mixed things up.

There are things to improve/fix like the additional slash in the path (https://github.com/owncloud/gallery/blob/master/ajax/thumbnail.php#L33), and there are also other issues to deal with like improper handling of .tif files. The point is, that .tif files are handled half way and this creates confusing error messages. (eg try to create a .tif image for preview which is programatically rejected (https://github.com/owncloud/gallery/blob/master/lib/thumbnail.php#L58) and then try to access the non written file with filemtime (https://github.com/owncloud/gallery/blob/master/ajax/thumbnail.php#L34)...). Right now I do not fully understand how image files are treated by gallery when core has processed them. But what I have seen is, that there are also some improvements possible for image files in core like at https://github.com/owncloud/core/blob/master/lib/private/image.php#L525.

I will close this issue and raise the right once at the rigt place

PVince81 commented 10 years ago

@mmattel thanks a lot for your feedback and analysis.

PVince81 commented 10 years ago

CC @georgehrke

I believe there is already a ticket about tif file handling.