No Code Attached Yet bug
avatar o-joomla-issues
o-joomla-issues
15 Apr 2024

Steps to reproduce the issue

Upload empty bitmap image (bmp,gif,jpg,jpeg,png)
(or on console: touch test.png)

Expected result

File list with all existing images

Actual result

Empty file list, no files are shown, not even non-zero files
URL changes to include folder name
Folder in left column folder is not highligted as "current"

System information (as much as possible)

Joomla! ‎5.0.3
PHP 8.3.4 as fpm-fcgi on nginx

Additional comments

Happens with empty bmp,gif,jpg,jpeg,png files but not with ico,pdf,svg
File list shows properly if you remove the empty images or rename them top non-image file extension

avatar o-joomla-issues o-joomla-issues - open - 15 Apr 2024
avatar o-joomla-issues o-joomla-issues - change - 15 Apr 2024
Labels Removed: ?
avatar joomla-cms-bot joomla-cms-bot - change - 15 Apr 2024
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 15 Apr 2024
avatar dgrammatiko
dgrammatiko - comment - 15 Apr 2024

Happens with empty bmp,gif,jpg,jpeg,png files but not with ico,pdf,svg

It's expected (code wise). The mime of the image files are checked through PHP functions which will obviously fail for an empty image:

public static function getMimeType($file, $isImage = false)
{
// If we can't detect anything mime is false
$mime = false;
try {
if ($isImage && \function_exists('exif_imagetype')) {
$mime = image_type_to_mime_type(exif_imagetype($file));
} elseif ($isImage && \function_exists('getimagesize')) {
$imagesize = getimagesize($file);
$mime = $imagesize['mime'] ?? false;
} elseif (\function_exists('mime_content_type')) {
// We have mime magic.
$mime = mime_content_type($file);
} elseif (\function_exists('finfo_open')) {
// We have fileinfo
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $file);
finfo_close($finfo);
}
} catch (\Exception $e) {
// If we have any kind of error here => false;
return false;
}
// If we can't detect the mime try it again
if ($mime === 'application/octet-stream' && $isImage === true) {
$mime = static::getMimeType($file, false);
}
if (
($mime === 'application/octet-stream' || $mime === 'image/svg' || $mime === 'image/svg+xml')
&& !$isImage && strtolower(pathinfo($file, PATHINFO_EXTENSION)) === 'svg' && self::isValidSvg($file, false)
) {
return 'image/svg+xml';
}
// We have a mime here
return $mime;
}

FWIW I had proposed a safer, faster alternative some time ago...

avatar Kubik-Rubik
Kubik-Rubik - comment - 15 Apr 2024

Such broken image files should be appropriately caught and displayed with a corresponding icon:

grafik

Please try to set the error level to None in the global settings and load the Media Manager again.

avatar o-joomla-issues
o-joomla-issues - comment - 15 Apr 2024

With error reporting set to none the folder contents is displayed as expected. I can see the above image.
With error reporting set to standard the initial issue shows up.

Additional info: browser console shows:
VM201:1 Uncaught SyntaxError: Unexpected token '<', "

"... is not valid JSON
at JSON.parse ()
at onSuccess (media-manager.min.js?3c55e4:1:84574)
at i.onreadystatechange (core.min.js?83f2c9:1:6174)
onSuccess @ media-manager.min.js?3c55e4:1
i.onreadystatechange @ core.min.js?83f2c9:1
XMLHttpRequest.send (async)
s @ core.min.js?83f2c9:1
r.request @ core.min.js?83f2c9:1
(anonymous) @ media-manager.min.js?3c55e4:1
getContents @ media-manager.min.js?3c55e4:1
getContents @ media-manager.min.js?3c55e4:5
(anonymous) @ media-manager.min.js?3c55e4:5
Store.dispatch @ media-manager.min.js?3c55e4:5
Store.dispatch @ media-manager.min.js?3c55e4:5
navigateTo @ media-manager.min.js?3c55e4:1
onItemClick @ media-manager.min.js?3c55e4:1
(anonymous) @ media-manager.min.js?3c55e4:1
(anonymous) @ media-manager.min.js?3c55e4:1
callWithErrorHandling @ media-manager.min.js?3c55e4:1
callWithAsyncErrorHandling @ media-manager.min.js?3c55e4:1
n @ media-manager.min.js?3c55e4:1


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/43279.

avatar o-joomla-issues
o-joomla-issues - comment - 15 Apr 2024

With error reporting set to simple the folder contents is displayed as expected also.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/43279.

avatar Kubik-Rubik
Kubik-Rubik - comment - 15 Apr 2024

Yes, this is expected behaviour in this case. If PHP writes errors, notices or warnings into the output, the JSON response is no longer valid, and the Media Manager cannot process the response correctly. So, this is the symptom of the issue but not the source.

We should ensure that built-in PHP calls to retrieve image information do not create such errors because a 0-byte image is processed like a valid one.

I solved it years ago in my extensions by checking for the file size first before running any further calls on the file. We could also apply the same logic to the local adapter for the Media Manager.

avatar richard67
richard67 - comment - 16 Apr 2024

We could also apply the same logic to the local adapter for the Media Manager.

I think that should be done, and as it’s a bug fix it should be done for the 4.4-dev branch if the issue happens also with 4.4.x. It will later be merged up into 5.1-dev by release managers.

avatar ralain
ralain - comment - 22 May 2024

We had a possibly related issue on a customer's site where they had uploaded an animated gif. This triggered the error:

imagecolorsforindex(): Argument #2 ($color) is out of range

in the Media Manager, and no images loaded.

Turns out Create Thumbnails was enabled in the "FileSystem - Local" plugin. Disabling Create Thumbnails fixed the error.

Animated gifs trigger the error on both 4.4 and 5.1 when Create Thumbnails is enabled.

avatar fgsw
fgsw - comment - 11 Oct 2024

and as it’s a bug fix - #43279 (comment)

@richard67 The issue hasn't the label bug.

avatar Quy
Quy - comment - 6 Nov 2024

@ralain See PR #44418

avatar Quy Quy - change - 6 Nov 2024
Labels Added: bug
avatar Quy Quy - labeled - 6 Nov 2024

Add a Comment

Login with GitHub to post a comment