Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix path of file_get_contents #28473

Merged
merged 2 commits into from
Aug 25, 2021
Merged

Fix path of file_get_contents #28473

merged 2 commits into from
Aug 25, 2021

Conversation

solracsf
Copy link
Member

@solracsf solracsf commented Aug 17, 2021

Try to fix #28370 and fix #27441

Avoid pre-pends the $path to the user's own storage.

Try to fix #28370  and #27441 

Avoid pre-pends the `$path` to the user's own storage.
@solracsf solracsf added the 3. to review Waiting for reviews label Aug 17, 2021
@ChristophWurst
Copy link
Member

Does this also work with anything other than a local filesystem?

@solracsf

This comment has been minimized.

@szaimen szaimen added this to the Nextcloud 23 milestone Aug 17, 2021
@kesselb
Copy link
Contributor

kesselb commented Aug 17, 2021

Does it work? ;) The "faulty" path rewrite is already happening in getLocalPath.

image

Trigger this faulty part / path is a bit tricky 🙈

  1. Don't have the exif module for php installed
  2. Comment the following code / let exif_imagetype return false:
    if (($info = getimagesize($fileName)) !== false) {
    return $info[2];
    }
    We want to generate a preview for a file that seems to be an image but we are unable to detect the type of the image and fallback to a default logic (that triggers this error)
  3. Previews are cached. To always trigger the preview generation comment:
  4. Set a breakpoint here:
    $this->resource = imagecreatefromstring(\OC\Files\Filesystem::file_get_contents(\OC\Files\Filesystem::getLocalPath($imagePath)));
  5. Upload some image file
  6. Move the image file to the trash
  7. Go to trash
  8. Happy debugging 🐛

Does this also work with anything other than a local filesystem?

I don't think it has too. All other methods / cases in the above switch-case are working with the local filesystem directly. No Nextcloud Api is used to access a image file.

$this->resource = imagecreatefromstring(file_get_contents($imagePath)); should work in a similar way to read the image content into a string (and not use any Nextcloud Api like the other cases).

@solracsf

This comment has been minimized.

@solracsf

This comment has been minimized.

@skjnldsv skjnldsv added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Aug 18, 2021
@solracsf solracsf added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Aug 18, 2021
Copy link
Member

@ChristophWurst ChristophWurst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 🐘

@ChristophWurst ChristophWurst merged commit 006aac9 into master Aug 25, 2021
@ChristophWurst ChristophWurst deleted the fix-file-get-contents branch August 25, 2021 07:28
@solracsf
Copy link
Member Author

solracsf commented Oct 4, 2021

Hey @ChristophWurst can this be backported? ;)

@kesselb
Copy link
Contributor

kesselb commented Oct 4, 2021

/backport to stable22

@kesselb
Copy link
Contributor

kesselb commented Oct 4, 2021

/backport to stable21

@kesselb
Copy link
Contributor

kesselb commented Oct 4, 2021

/backport to stable20

@backportbot-nextcloud
Copy link

The backport to stable20 failed. Please do this backport manually.

@backportbot-nextcloud
Copy link

The backport to stable21 failed. Please do this backport manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews
Projects
None yet
6 participants