Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin crashes with improper input #634

Open
Firmware-Repairman opened this issue May 19, 2023 · 1 comment
Open

Plugin crashes with improper input #634

Firmware-Repairman opened this issue May 19, 2023 · 1 comment

Comments

@Firmware-Repairman
Copy link

The function get_files_for_unique_filename_file_list() returns a boolean (false) if the parameter passed to scandir() is not a directory. This causes the filter where it is used to crash. If scandir() returns false the function should return an empty array.

Function

	/**
	 * Override the files used for wp_unique_filename() comparisons
	 *
	 * @param array|null $files
	 * @param string $dir
	 * @return array
	 */
	public function get_files_for_unique_filename_file_list( ?array $files, string $dir, string $filename ) : array {
		$name = pathinfo( $filename, PATHINFO_FILENAME );
		// The s3:// streamwrapper support listing by partial prefixes with wildcards.
		// For example, scandir( s3://bucket/2019/06/my-image* )
		return scandir( trailingslashit( $dir ) . $name . '*' );
	}

Error trace

Fatal error: Uncaught Error: Return value of S3_Uploads\Plugin::get_files_for_unique_filename_file_list() must be of the type array, bool returned in /srv/htdocs/wp-content/plugins/s3-uploads/inc/class-plugin.php on line 668

Call stack:

S3_Uploads\Plugin::get_files_for_unique_filename_file_list()
wp-includes/class-wp-hook.php:308
WP_Hook::apply_filters()
wp-includes/plugin.php:205
apply_filters()
wp-includes/functions.php:2643
...

@rasmuswinter
Copy link

Duplicate of issue #630

Fixed in PR #637

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants