You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
OC_Image doesn't always set imageType correctly #18645
OC_Image has imageType = IMAGETYPE_PNG by default.
Several load functions like loadFromBase64, loadFromData, loadFromFileHandle, load don't (always) set imageType to the correct type of image loaded.
For example, if you load a JPEG with loadFromData() imageType remains on IMAGETYPE_PNG.
Due to this, some other image processing functions don't correctly work or cause errors.
For example you get error "OC_Image->fixOrientation() Image is not a JPEG" if you call fixOrientation() on a JPEG loaded with loadFromData even though it's in fact a JPEG.
imageType should always match the type of image. All functions seems to set mimeType correctly but lack to set imageType...
I don't fully understand how everything in OC_Image works together and there seem to be some more issues to get fixOrientation working. Commit 88db5a365b53e713fe31bcc032fc22e48a56accc sets the imagetype work loadFromData() and loadFromBase64(). It's still missing for load() if it gets passed a resource.
With this commit, fixOrientation fails with "OC_Image->fixOrientation() No readable file path set" if I upload a jpg into a contact. As it doesn't come from a file it looks like a more general issue here how to handle images loaded from other sources than files.
So I think someone who has a better understanding of that should have a look at this as further changes may have implications I don't see...
@gvde The first step would be to list all the methods in image which require a proper imagetype to be set and then the best thing to do is to provide a PR so that we can test various scenarios. The unit/integration tests of Preview should give us a first indication of if there are side-effects.
Has this issue been fixed in 10.0.9.5? Reason for asking is that EXIF based image rotation is failing for all JPG images in my vanilla 10.0.9.5 installation.
Looking at the code, it seems that fixOrientation is failing because loadFromFileHandle() does not set the imageType but I'm not an expert.
Relevant log file lines...
{"reqId":"BYsRLO4mFkPyHhjYrTDl","level":0,"time":"2018-08-22T20:03:50+02:00","remoteAddr":"172.16.172.83","user":"admin","app":"core","method":"GET","url":"\/owncloud\/index.php\/apps\/gallery\/thumbnails?ids=16&scale=2&square=0&requesttoken=EgooBxMNRR5vUggLO0thImBAA18VGDNhYC0iUhMoeQY%3D%3AuPDdC8tSDkPZbyTRStInvRW43iFfPfOgBf967XtJVkM%3D","message":"Generating preview for \"\/admin\/files\/IMG_1928.JPG\" with \"OC\\Preview\\JPEG\""} {"reqId":"BYsRLO4mFkPyHhjYrTDl","level":0,"time":"2018-08-22T20:03:50+02:00","remoteAddr":"172.16.172.83","user":"admin","app":"core","method":"GET","url":"\/owncloud\/index.php\/apps\/gallery\/thumbnails?ids=16&scale=2&square=0&requesttoken=EgooBxMNRR5vUggLO0thImBAA18VGDNhYC0iUhMoeQY%3D%3AuPDdC8tSDkPZbyTRStInvRW43iFfPfOgBf967XtJVkM%3D","message":"OC_Image->fixOrientation() Image is not a JPEG."} {"reqId":"BYsRLO4mFkPyHhjYrTDl","level":0,"time":"2018-08-22T20:03:50+02:00","remoteAddr":"172.16.172.83","user":"admin","app":"core","method":"GET","url":"\/owncloud\/index.php\/apps\/gallery\/thumbnails?ids=16&scale=2&square=0&requesttoken=EgooBxMNRR5vUggLO0thImBAA18VGDNhYC0iUhMoeQY%3D%3AuPDdC8tSDkPZbyTRStInvRW43iFfPfOgBf967XtJVkM%3D","message":"OC_Image->fixOrientation() Orientation: -1"}
I have also noticed #29319, which replaced loadFromFile, to loadFromFileHandle method.
Using objectstore
Using gallery to verify the preview with
The preview from object store version preview for the image file
The preview doesn't come up properly.
On the other hand preview of text file under version panel
PR
Created PR: #34297
Let me know the suggestion if this approach looks good @PVince81@VicDeo
Unit test is not added, the coverage is happening.
Verify the preview of text files
Verify public link preview
Verify trashbin preview
PS: The idea behind public link preview and trashbin preview is inspired from comment : #29319 (review)
@sharidas please also test with external storage and make sure the file is not downloaded to temp space when on local storage. With ext storage, getLocalFile should download the file from the ext storage to temp space.
@sharidas please also test with external storage and make sure the file is not downloaded to temp space when on local storage. With ext storage, getLocalFile should download the file from the ext storage to temp space.
While testing with external storage SFTP, I have noticed that getLocalFile method returns file of /tmp/oc_tmp_*.jpg ( obviously for a jpg file ). And when I try to check the file in my local machine:
✘ sujith@sujith-ownCloud ~/test/owncloud2 stable10 ls /tmp/oc_tmp_y9p5iR-.jpg
ls: cannot access '/tmp/oc_tmp_y9p5iR-.jpg': No such file or directory
✘ sujith@sujith-ownCloud ~/test/owncloud2 stable10
So I believe it is not downloaded to the tmp location. Let me know if we agree with this observation.
@sharidas also verify version preview: open versions panel and see the thumbnail orientation
Regarding preview for version, I am missing bits how to get the version update for image :( I mean after uploading the file, may I know how to update the image so that version panel lists previous version?
Regarding preview for text file the version panel, it is working properly
Regarding preview for image, the version panel is as shown here
@sharidas depending on your distro the tmp files might be in chroot somewhere in /tmp. try searching for the exact file name. you'll likely need to set a breakpoint to prevent the file getting deleted
Tried to upload an image file to local storage ( not the sftp storage or the folder ), the file path points to the data directory where it resides. Meaning its not copied to the temperory folder ( say /tmp or so )
Tried to upload an image to sftp storage and below is the observation:
By this time the $tmpFile is /tmp/oc_tmp_H1JRmt-.jpg and this file is found in my local machine at /tmp/systemd-private-012a7f2341b643d9881e8537cbb42431-apache2.service-epLRm1/tmp/oc_tmp_H1JRmt-.jpg
After the image is successfully uploaded, I tried:
✘ sujith@sujith-ownCloud /tmp sudo ls /tmp/systemd-private-012a7f2341b643d9881e8537cbb42431-apache2.service-epLRm1/tmp/oc_tmp_H1JRmt-.jpg
ls: cannot access '/tmp/systemd-private-012a7f2341b643d9881e8537cbb42431-apache2.service- epLRm1/tmp/oc_tmp_H1JRmt-.jpg': No such file or directory
✘ sujith@sujith-ownCloud /tmp
So yes with external storage it is downloaded to the temp space.
fix will be in 10.1.1 (10.1.0 already is in code freeze)
Predicting the specific number of a future version is a risky undertaking ;)
There was a "hotfix patch" for a particular bug and that ended up being the version called 10.1.1
The fix for the issue here was backported to stable10 in PR #34356. That will be in the next "regular release". At the time of writing this post the release numbering "will be" 10.2 - but of course the next release could be 10.1.210.2 or 11.0 - that just depends on the semver-related content of whatever is in the release.
Thank you for the explanation :) , it's very helpful. I mainly wanted to save other readers here the hassle of having to find this out the hard way. And I wanted to verify that this patch is indeed coming to a release.
Activity
karlitschek commentedon Aug 29, 2015
Do you want to open a pull request?
gvde commentedon Aug 29, 2015
I don't fully understand how everything in OC_Image works together and there seem to be some more issues to get fixOrientation working. Commit 88db5a365b53e713fe31bcc032fc22e48a56accc sets the imagetype work loadFromData() and loadFromBase64(). It's still missing for load() if it gets passed a resource.
With this commit, fixOrientation fails with "OC_Image->fixOrientation() No readable file path set" if I upload a jpg into a contact. As it doesn't come from a file it looks like a more general issue here how to handle images loaded from other sources than files.
So I think someone who has a better understanding of that should have a look at this as further changes may have implications I don't see...
PVince81 commentedon Aug 30, 2015
@georgehrke @oparoz
oparoz commentedon Oct 4, 2015
@gvde The first step would be to list all the methods in image which require a proper imagetype to be set and then the best thing to do is to provide a PR so that we can test various scenarios. The unit/integration tests of Preview should give us a first indication of if there are side-effects.
oparoz commentedon Oct 4, 2015
OK, quick assessment.
Imagetype is only set when an image is loaded from file
Affected methods:
getOrientation()Should break orientation supportpreciseResize()Should break transparency supportcenterCrop()Should break transparency supportcrop()Should break transparency supportSo, it would be good to get a PR which also includes setting the imagetype for resources-
PVince81 commentedon Apr 6, 2017
Please try again with 9.1.4 or 10.0 beta
zero0cool0 commentedon Aug 22, 2018
Has this issue been fixed in 10.0.9.5? Reason for asking is that EXIF based image rotation is failing for all JPG images in my vanilla 10.0.9.5 installation.
Looking at the code, it seems that fixOrientation is failing because
loadFromFileHandle()does not set the imageType but I'm not an expert.Relevant log file lines...
{"reqId":"BYsRLO4mFkPyHhjYrTDl","level":0,"time":"2018-08-22T20:03:50+02:00","remoteAddr":"172.16.172.83","user":"admin","app":"core","method":"GET","url":"\/owncloud\/index.php\/apps\/gallery\/thumbnails?ids=16&scale=2&square=0&requesttoken=EgooBxMNRR5vUggLO0thImBAA18VGDNhYC0iUhMoeQY%3D%3AuPDdC8tSDkPZbyTRStInvRW43iFfPfOgBf967XtJVkM%3D","message":"Generating preview for \"\/admin\/files\/IMG_1928.JPG\" with \"OC\\Preview\\JPEG\""} {"reqId":"BYsRLO4mFkPyHhjYrTDl","level":0,"time":"2018-08-22T20:03:50+02:00","remoteAddr":"172.16.172.83","user":"admin","app":"core","method":"GET","url":"\/owncloud\/index.php\/apps\/gallery\/thumbnails?ids=16&scale=2&square=0&requesttoken=EgooBxMNRR5vUggLO0thImBAA18VGDNhYC0iUhMoeQY%3D%3AuPDdC8tSDkPZbyTRStInvRW43iFfPfOgBf967XtJVkM%3D","message":"OC_Image->fixOrientation() Image is not a JPEG."} {"reqId":"BYsRLO4mFkPyHhjYrTDl","level":0,"time":"2018-08-22T20:03:50+02:00","remoteAddr":"172.16.172.83","user":"admin","app":"core","method":"GET","url":"\/owncloud\/index.php\/apps\/gallery\/thumbnails?ids=16&scale=2&square=0&requesttoken=EgooBxMNRR5vUggLO0thImBAA18VGDNhYC0iUhMoeQY%3D%3AuPDdC8tSDkPZbyTRStInvRW43iFfPfOgBf967XtJVkM%3D","message":"OC_Image->fixOrientation() Orientation: -1"}28 remaining items
sharidas commentedon Jan 28, 2019
Analysis
I tried to figure out that there is something wrong with https://github.com/owncloud/core/blob/master/lib/private/legacy/image.php#L386, which is causing the rotation of the image shared #18645 (comment). I will update more regarding the same in this comment. Since this analysis is in the initial stage, the more information found would lead us to the actual problem.
Found a method
loadFromFile()in https://github.com/owncloud/core/blob/master/lib/private/legacy/image.php#L495.If we use this method instead of
loadFromFileHandle(), in https://github.com/owncloud/core/blob/master/lib/private/Preview/Image.php#L49, I found the orientation of exif image gets corrected. By uploading a few files, I did not found any impact on performance, as such ( at least notable to my eyes ). I tried with a few sample exif images which has orientation. And withoutloadFromFile()files are seen as mentioned in the issue. After usingloadFromFile(), they were getting corrected.I have also noticed #29319, which replaced
loadFromFile, toloadFromFileHandlemethod.Using objectstore
Using gallery to verify the preview with

The preview from object store version preview for the image file


The preview doesn't come up properly.
On the other hand preview of text file under version panel
PR
Created PR: #34297
Let me know the suggestion if this approach looks good @PVince81 @VicDeo
Unit test is not added, the coverage is happening.
Verify the preview of text files

Verify public link preview

Verify trashbin preview

PS: The idea behind public link preview and trashbin preview is inspired from comment : #29319 (review)
PVince81 commentedon Jan 30, 2019
@sharidas please also test with external storage and make sure the file is not downloaded to temp space when on local storage. With ext storage,
getLocalFileshould download the file from the ext storage to temp space.PVince81 commentedon Jan 30, 2019
@sharidas also verify version preview: open versions panel and see the thumbnail orientation
sharidas commentedon Jan 30, 2019
While testing with external storage SFTP, I have noticed that
getLocalFilemethod returns file of/tmp/oc_tmp_*.jpg( obviously for a jpg file ). And when I try to check the file in my local machine:So I believe it is not downloaded to the tmp location. Let me know if we agree with this observation.
sharidas commentedon Jan 30, 2019
Regarding preview for version, I am missing bits how to get the version update for image :( I mean after uploading the file, may I know how to update the image so that version panel lists previous version?
Regarding preview for text file the version panel, it is working properly

Regarding preview for image, the version panel is as shown here

PVince81 commentedon Jan 30, 2019
@sharidas depending on your distro the tmp files might be in chroot somewhere in /tmp. try searching for the exact file name. you'll likely need to set a breakpoint to prevent the file getting deleted
sharidas commentedon Jan 31, 2019
Analysis with external storage
Scenario by having SFTP as externa storage
$tmpFileis/tmp/oc_tmp_H1JRmt-.jpgand this file is found in my local machine at/tmp/systemd-private-012a7f2341b643d9881e8537cbb42431-apache2.service-epLRm1/tmp/oc_tmp_H1JRmt-.jpg@PVince81 I assume this is what you wanted me to look at from #18645 (comment) and #18645 (comment)
PVince81 commentedon Feb 1, 2019
fix will be in 10.1.1 (10.1.0 already is in code freeze)
depeje commentedon Apr 9, 2019
The fix doesn't seem to be in 10.1.1: https://github.com/owncloud/core/blob/v10.1.1/lib/private/Preview/Image.php
phil-davis commentedon Apr 9, 2019
Predicting the specific number of a future version is a risky undertaking ;)
There was a "hotfix patch" for a particular bug and that ended up being the version called
10.1.1The fix for the issue here was backported to
stable10in PR #34356. That will be in the next "regular release". At the time of writing this post the release numbering "will be"10.2- but of course the next release could be10.1.210.2or11.0- that just depends on the semver-related content of whatever is in the release.depeje commentedon Apr 9, 2019
Thank you for the explanation :) , it's very helpful. I mainly wanted to save other readers here the hassle of having to find this out the hard way. And I wanted to verify that this patch is indeed coming to a release.
PVince81 commentedon Apr 16, 2019
you can already test with the RC1 if you like: https://central.owncloud.org/t/owncloud-server-10-2-0-rc1-released/19499