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

Exception - imagesx(): Argument #1 ($image) must be of type GdImage, bool given #35

Open
dustinbrisebois opened this issue Jan 17, 2024 · 3 comments

Comments

@dustinbrisebois
Copy link

MDL 4.1 getting this error:

line 386 of /mod/mediagallery/classes/item.php: TypeError thrown
line 386 of /mod/mediagallery/classes/item.php: call to imagesx()
line 296 of /mod/mediagallery/classes/item.php: call to mod_mediagallery\item->get_image_resized()
line 495 of /mod/mediagallery/classes/item.php: call to mod_mediagallery\item->generate_image_by_type()
line 622 of /mod/mediagallery/classes/item.php: call to mod_mediagallery\item->get_stored_file_by_type()
line 340 of /mod/mediagallery/classes/gallery.php: call to mod_mediagallery\item->get_image_url()
line 204 of /mod/mediagallery/renderer.php: call to mod_mediagallery\gallery->get_thumbnail()
line 173 of /mod/mediagallery/renderer.php: call to mod_mediagallery_renderer->gallery_list_item()
line 128 of /mod/mediagallery/classes/viewcontroller.php: call to mod_mediagallery_renderer->render_collection()
line 64 of /mod/mediagallery/classes/viewcontroller.php: call to mod_mediagallery\viewcontroller->action_viewcollection()
line 144 of /mod/mediagallery/view.php: call to mod_mediagallery\viewcontroller->display_action()

@dustinbrisebois
Copy link
Author

I believe this issue has to do with this:

https://github.com/open-lms-open-source/moodle-mod_mediagallery/blob/876b1892fc27fa3098cd02c385998f2bc5bc7a86/classes/item.php#L333C70-L333C70

https://www.php.net/manual/en/function.imagecreatefromstring.php

Returns a GDImage OR False - however if the encoding and/or image are not processable it errors out.

@dustinbrisebois
Copy link
Author

The problem is there is no sanity check if the file_get_contents is empty. In the event that an image isn't available (for whatever reason) the system automatically fails to check if the contents are good to process, and if the image is even of the right type.

@dustinbrisebois
Copy link
Author

This

        $content = file_get_contents($tempfile);
        if (strlen($contents) == 0) {
            return False;
        }

is a very ugly fix but it does solve the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant