Cannot upload docx files after updating to 3.0.10

Created on 31 December 2023, 11 months ago
Updated 18 January 2024, 10 months ago

Problem/Motivation

docker-compose.yml
version: '3'

services:
drupal:
image: drupal
ports:
- 80:80
db:
image: mariadb
environment:
MYSQL_DATABASE: drupal
MYSQL_ROOT_PASSWORD: password

composer require drush/drush
composer require 'drupal/imce:^3.0'
drush en imce

http://localhost/admin/imce/browser
Uploaded aa.docx.

The following message is displayed and cannot upload.

The specified file aa.docx could not be uploaded.
Only files with the following extensions are allowed: jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp.

I was able to upload aa.doc.

drush pmu imce
composer remove drupal/imce
composer require 'drupal/imce:3.0.9'
drush en imce

I can upload aa.docx

/admin/config/media/imce/admin?destination=/admin/config/media/imce

Allowed file extensions is *.

Drupal 10.1.7
PHP 8.2.14

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

πŸ‡―πŸ‡΅Japan ytsuhako

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

Comments & Activities

  • Issue created by @ytsuhako
  • πŸ‡―πŸ‡΅Japan ytsuhako

    I can upload if I type docx instead of asterisks in the allowed extensions.

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

    I'm getting the same error with the asterisk meant to allow all file types. Setting a specific list of file types works at least.

  • πŸ‡―πŸ‡΅Japan ytsuhako

    /opt/drupal/web/modules/contrib/imce/src/Plugin/ImcePlugin/Upload.php

    if ($exts !== '*') {
    $validators['file_validate_extensions'] = [$exts];
    }

    It worked when changed to the following.

    if ($exts !== '*') {
    $validators['file_validate_extensions'] = [$exts];
    } else {
    $validators['file_validate_extensions'] = [Null];
    }

    I made this change because it is handled as follows in the core.

    /opt/drupal/web/core/modules/file/src/Upload/FileUploadHandler.php

    protected function handleExtensionValidation(array &$validators): string {
    // Build a list of allowed extensions.
    if (isset($validators['file_validate_extensions'])) {
    if (!isset($validators['file_validate_extensions'][0])) {
    // If 'file_validate_extensions' is set and the list is empty then the
    // caller wants to allow any extension. In this case we have to remove the
    // validator or else it will reject all extensions.
    unset($validators['file_validate_extensions']);
    }
    }
    else {
    // No validator was provided, so add one using the default list.
    // Build a default non-munged safe list for
    // \Drupal\system\EventSubscriber\SecurityFileUploadEventSubscriber::sanitizeName().
    $validators['file_validate_extensions'] = [self::DEFAULT_EXTENSIONS];
    }
    return $validators['file_validate_extensions'][0] ?? '';
    }

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.4 + Environment: PHP 8.2 & MySQL 8
    last update 11 months ago
    55 pass
    • ufku β†’ committed cc511420 on 3.x
      Issue #3411471: Fix file validation not allowing all extensions.
      
      Use...
  • Status changed to Fixed 11 months ago
  • Fixed in 3.0.11
    Thanks for reporting.

  • πŸ‡―πŸ‡΅Japan ytsuhako

    Problem solved for me.
    Thanks a lot.

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

    All fixed for me! Thanks!

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

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

    Not sure if this one is fixed... still have the issue after updating to 3.0.12 and core 10.2.7.

    I am able to upload files when I put a wildcard (*) in the "Allowed file extensions field", but I'm still getting the error when I limit to certain extensions.

Production build 0.71.5 2024