Too-large files in ZIPs cause fatal error

Created on 3 September 2025, 30 days ago

Problem/Motivation

If a media type has a file size constraint on its file field, uploading a zip file that contains a too-large file will cause the batch processing to fail with a Type Error.

Steps to reproduce

  1. Install the latest Drupal core 11.x using the standard profile.
  2. Enable media_bulk_zip_upload and its dependencies (core Media module).
  3. Log in as an administrator.
  4. At /admin/config/media/media-bulk-zip-upload-config, enable ZIP uploads for the Document media type.
  5. At /admin/structure/media/manage/document/form-display, customize the media_bulk_zip_upload form display to show only the needed fields (remove the Document field, for example).
  6. At /admin/structure/media/manage/document/fields, set a maximum upload file size of 1 MB.
  7. Create a ZIP file that includes several files smaller than 1 MB and at least one bigger than 1 MB.
  8. At /admin/content/media, press Bulk upload Document media.
  9. Upload your ZIP file.
  10. Note there is an Ajax error: TypeError: Drupal\Component\Utility\Html::escape(): Argument #1 ($text) must be of type string, array given, called in /var/www/html/core/lib/Drupal/Component/Render/FormattableMarkup.php on line 238 in Drupal\Component\Utility\Html::escape() (line 433 of /var/www/html/core/lib/Drupal/Component/Utility/Html.php).

Stack trace:

#0 /var/www/html/core/lib/Drupal/Component/Render/FormattableMarkup.php(238): Drupal\Component\Utility\Html::escape()
#1 /var/www/html/core/lib/Drupal/Component/Render/FormattableMarkup.php(187): Drupal\Component\Render\FormattableMarkup::placeholderEscape()
#2 /var/www/html/core/lib/Drupal/Core/StringTranslation/TranslatableMarkup.php(195): Drupal\Component\Render\FormattableMarkup::placeholderFormat()
#3 /var/www/html/core/lib/Drupal/Component/Utility/ToStringTrait.php(15): Drupal\Core\StringTranslation\TranslatableMarkup->render()
#4 /var/www/html/core/lib/Drupal/Core/Messenger/Messenger.php(54): Drupal\Core\StringTranslation\TranslatableMarkup->__toString()
#5 /var/www/html/core/lib/Drupal/Core/Messenger/Messenger.php(46): Drupal\Core\Messenger\Messenger->addMessage()
#6 /var/www/html/modules/contrib/media_bulk_zip_upload/src/Form/MediaBulkZipUploadForm.php(254): Drupal\Core\Messenger\Messenger->addError()
#7 /var/www/html/core/includes/batch.inc(297): Drupal\media_bulk_zip_upload\Form\MediaBulkZipUploadForm::processOneFile()
#8 /var/www/html/core/includes/batch.inc(138): _batch_process()
#9 /var/www/html/core/includes/batch.inc(95): _batch_do()
#10 /var/www/html/core/modules/system/src/Controller/BatchController.php(52): _batch_page()
#11 [internal function]: Drupal\system\Controller\BatchController->batchPage()
#12 /var/www/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
#13 /var/www/html/core/lib/Drupal/Core/Render/Renderer.php(633): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#14 [internal function]: Drupal\Core\Render\Renderer::Drupal\Core\Render\{closure}()
#15 /var/www/html/core/lib/Drupal/Core/Render/Renderer.php(634): Fiber->start()
#16 /var/www/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(121): Drupal\Core\Render\Renderer->executeInRenderContext()
#17 /var/www/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
#18 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(183): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#19 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#20 /var/www/html/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle()
#21 /var/www/html/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#22 /var/www/html/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#23 /var/www/html/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle()
#24 /var/www/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(116): Drupal\big_pipe\StackMiddleware\ContentLength->handle()
#25 /var/www/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(90): Drupal\page_cache\StackMiddleware\PageCache->pass()
#26 /var/www/html/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle()
#27 /var/www/html/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#28 /var/www/html/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(53): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#29 /var/www/html/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle()
#30 /var/www/html/core/lib/Drupal/Core/DrupalKernel.php(715): Drupal\Core\StackMiddleware\StackedHttpKernel->handle()
#31 /var/www/html/index.php(19): Drupal\Core\DrupalKernel->handle()
#32 {main}

From the stack trace, it looks like the file size validation is happening, but something is wrong with a placeholder in the error message.

Proposed resolution

Check what's going on with the error message, is there something specific about too-large files that triggers the issue, or would it happen with any validation error?

Remaining tasks

MR and test.

User interface changes

None.

API changes

None.

Data model changes

None.

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States cboyden

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

Merge Requests

Comments & Activities

  • Issue created by @cboyden
  • πŸ‡ΊπŸ‡ΈUnited States cboyden

    The problem is this code in MediaBulkZipUploadForm::processOneFile():

    $violations = $media->validate();
          if (\count($violations)) {
            \Drupal::service('messenger')
              ->addError(new TranslatableMarkup('Could not create media for %file: @messages', [
                '%file' => $filename,
                '@messages' => \array_map(static function (ConstraintViolation $violation) {
                  return $violation->getMessage();
                }, \iterator_to_array($violations)),
              ]));
            return;
          }
    

    You can't pass an array into a placeholder in a TranslatableMarkup object. The $violations variable is an array, and the data returned from the callback function is also an array. The code should either use only the first violation message, or concatenate the error messages.

    I'll work on an MR for this.

  • Pipeline finished with Failed
    22 days ago
    Total: 141s
    #596386
Production build 0.71.5 2024