Problem/Motivation

When uploading a file whose name already exists on S3 but the s3fs cache table has no matching records (stale cache), AjaxController::createFileKey() crashes on line 172 with:

ValueError: max(): Argument #1 ($value) must contain at least one element in max()

The call max(array_keys($results)) fails because $results is empty when the LIKE query on s3fs_file returns no matching URIs, but the file already exists on S3 (detected by doesObjectExistV2).

Steps to reproduce

  1. Upload a file via an s3fs_cors widget (e.g. a video file)
  2. Upload a file with the same name again
  3. If the s3fs cache table is stale (does not contain the first file's record), the rename logic enters the cache-stale branch on line 167 but crashes because $results is empty

Proposed resolution

Guard the max() call on line 172 so it defaults to 0 when $results is empty:

$suffix = $results !== [] ? max(array_keys($results)) : 0;

Remaining tasks

Review and commit the merge request.

User interface changes

None.

API changes

None.

Data model changes

None.

Issue fork s3fs_cors-3592725

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

ethant created an issue. See original summary.

  • heddn committed 5f40035e on 8.x-1.x authored by ethant
    fix: #3592725 ValueError in createFileKey() when results array is empty...
heddn’s picture

Status: Active » Fixed

Thanks for the contribution

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

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

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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