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.

Issue fork brightcove-3278712

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

muriqui created an issue. See original summary.

muriqui’s picture

Status: Active » Needs review

Push proposed fix as MR !20.

muriqui’s picture

StatusFileSize
new657 bytes

Patch file for those who may need it.

eveyrat’s picture

Hi,
I'm having the exact same issue and confirm that the patch fixed the issue.
Thanks a lot @muriqui

yce’s picture

StatusFileSize
new971 bytes

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.

awolfey’s picture

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

yce’s picture

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.

yce’s picture

Status: Needs review » Fixed

I'm going to assume it is fixed.

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.