Skip to content

OC_Image doesn't always set imageType correctly #18645

Closed

Description

@gvde

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...

Activity

  1. karlitschek commented on Aug 29, 2015

    @karlitschek
    Contributor

    Do you want to open a pull request?

  2. gvde commented on Aug 29, 2015

    @gvde
    Author

    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...

  3. PVince81 commented on Aug 30, 2015

    @PVince81
    Contributor
  4. oparoz commented on Oct 4, 2015

    @oparoz
    Contributor

    @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.

  5. oparoz commented on Oct 4, 2015

    @oparoz
    Contributor

    OK, quick assessment.

    Imagetype is only set when an image is loaded from file

    Affected methods:

    • getOrientation() Should break orientation support
    • preciseResize() Should break transparency support
    • centerCrop()Should break transparency support
    • crop()Should break transparency support

    So, it would be good to get a PR which also includes setting the imagetype for resources-

  6. added this to the backlog milestone on Mar 3, 2016
  7. PVince81 commented on Apr 6, 2017

    @PVince81
    Contributor

    Please try again with 9.1.4 or 10.0 beta

  8. zero0cool0 commented on Aug 22, 2018

    @zero0cool0

    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"}

  9. 28 remaining items

  10. added this to the development milestone on Jan 28, 2019
  11. sharidas commented on Jan 28, 2019

    @sharidas
    Contributor

    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 without loadFromFile() files are seen as mentioned in the issue. After using loadFromFile(), they were getting corrected.

    I have also noticed #29319, which replaced loadFromFile, to loadFromFileHandle method.

    Using objectstore

    Using gallery to verify the preview with
    objectstore_preview

    The preview from object store version preview for the image file
    version_object_store_preview
    The preview doesn't come up properly.
    On the other hand preview of text file under version panel
    objectstore_text_preview_version

    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
      text_preview

    • Verify public link preview
      image_publink_preview

    • Verify trashbin preview
      trashbin_preview

    PS: The idea behind public link preview and trashbin preview is inspired from comment : #29319 (review)

  12. PVince81 commented on Jan 30, 2019

    @PVince81
    Contributor

    @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.

  13. PVince81 commented on Jan 30, 2019

    @PVince81
    Contributor

    @sharidas also verify version preview: open versions panel and see the thumbnail orientation

  14. sharidas commented on Jan 30, 2019

    @sharidas
    Contributor

    @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.

  15. sharidas commented on Jan 30, 2019

    @sharidas
    Contributor

    @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
    text_version

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

  16. PVince81 commented on Jan 30, 2019

    @PVince81
    Contributor

    @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

  17. sharidas commented on Jan 31, 2019

    @sharidas
    Contributor

    Analysis with external storage

    Scenario by having SFTP as externa storage
    1. 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 )
    2. Tried to upload an image to sftp storage and below is the observation:
      1. The code reaches here https://github.com/owncloud/core/blob/master/lib/private/Files/Storage/Common.php#L254
      2. And then https://github.com/owncloud/core/blob/master/lib/private/Files/Storage/LocalTempFileTrait.php#L48
      3. And reaches https://github.com/owncloud/core/blob/master/lib/private/Files/Storage/LocalTempFileTrait.php#L77
      4. 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
      5. 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 
        
      6. So yes with external storage it is downloaded to the temp space.

    @PVince81 I assume this is what you wanted me to look at from #18645 (comment) and #18645 (comment)

  18. PVince81 commented on Feb 1, 2019

    @PVince81
    Contributor

    fix will be in 10.1.1 (10.1.0 already is in code freeze)

  19. phil-davis commented on Apr 9, 2019

    @phil-davis
    Contributor

    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.2 10.2 or 11.0 - that just depends on the semver-related content of whatever is in the release.

  20. depeje commented on Apr 9, 2019

    @depeje

    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.

  21. PVince81 commented on Apr 16, 2019

    @PVince81
    Contributor
  22. locked as resolved and limited conversation to collaborators on Apr 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions