humanmade / S3-Uploads

The WordPress Plugin to Store Uploads on Amazon S3
1.92k stars 389 forks source link

fix readdir bug from PHP 8 substr change #661

Closed sc0tth0lden closed 4 months ago

sc0tth0lden commented 8 months ago

As of PHP 8.0, substr will return empty string rather than false in certain circumstances.

From https://www.php.net/manual/en/function.substr.php : 8.0.0 The function returns an empty string where it previously returned false.

Due to this change, this implementation of readdir in S3-Uploads behaves incorrectly. In particular, this common pattern: while (($file = readdir($dh)) !== false){ which is used in gravityforms, becomes an infinite loop since the while loop just keeps getting an empty string rather than false.

This can lead to a crazy high AWS S3 list line item on your monthly bill. I recommend merging in this change right away to avoid this situation.

hm-backport[bot] commented 4 months ago

The backport to v3-branch failed:

Commits ["ddee8f18144a45c1b1eaa47f127ab52a22e43690","c498617525b55936a8ab5a22226629f2641865f2","8393c9247bba12510d7ecb8f6235b03c7b20059c"] could not be cherry-picked on top of v3-branch

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub.
git fetch
# Create new working tree.
git worktree add .worktrees/backport v3-branch
# Navigate to the new directory.
cd .worktrees/backport
# Cherry-pick all the commits of this pull request and resolve the likely conflicts.
git cherry-pick ddee8f18144a45c1b1eaa47f127ab52a22e43690 c498617525b55936a8ab5a22226629f2641865f2 8393c9247bba12510d7ecb8f6235b03c7b20059c
# Create a new branch with these backported commits.
git checkout -b backport-661-to-v3-branch
# Push it to GitHub.
git push --set-upstream origin backport-661-to-v3-branch
# Go back to the original working tree.
cd ../..
# Delete the working tree.
git worktree remove .worktrees/backport

Then, create a pull request where the base branch is v3-branch and the compare/head branch is backport-661-to-v3-branch.