BrightcoveVideo::saveImage() throws an exception when using S3fs

Created on 4 May 2022, over 2 years ago
Updated 8 August 2024, 5 months ago

Problem/Motivation

When used in conjunction with the S3 File System β†’ module, thumbnail generation throws an exception:

TypeError: md5_file() expects parameter 1 to be a valid path, bool given in md5_file() (line 195 of /var/www/web/modules/contrib/brightcove/src/Entity/BrightcoveVideo.php)

Steps to reproduce

  1. Install both the brightcove and s3fs modules.
  2. Configure Brightcove.
  3. Configure S3fs and enable the s3fs.use_s3_for_public option so that S3 takes over the public:// file handler.
  4. Run the Brightcove cron job and check the error log.

Proposed resolution

The problem is caused by lines 194 and 195 of BrightcoveVideo:

$file_path = $file_system->realpath($file->getFileUri());
$file_md5 = md5_file($file_path);

With the s3fs.use_s3_for_public option enabled, the S3 module replaces the public:// file handler with its own. Because S3 is a remote stream wrapper, realpath() will return false, thus triggering the exception when that is passed to md5_file(). This could be solved by changing line 195 to set $file_md5 to false if the $file_path is false, like so:

$file_md5 = $file_path ? md5_file($file_path) : FALSE;

This is essentially the same result as if md5_file() had failed to calculate the file's hash, which is arguably what is happening here given that there isn't a standard method for getting a file's MD5 hash from a remote stream.

πŸ› Bug report
Status

Needs review

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States muriqui

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡­πŸ‡ΊHungary yce

    Hi,

    I would still try to calculate the hash for the file in case of remote paths.

    Seems like passing the file URI as-is to the md5_file() function works.
    I've also added a condition to make sure that the file exist before the hash calculation is attempted.

    Please let me know if it works for you as well.

  • πŸ‡ΊπŸ‡ΈUnited States awolfey

    I encountered this error in a different situation, and the patch in #6 also works for me. Thanks.

  • πŸ‡­πŸ‡ΊHungary yce

    Is it still an issue with Drupal 10.2 (or above) and Brightcove 3.2.0?

    As part of another issue I've just tested s3fs and I did not notice any errors now.

Production build 0.71.5 2024