In file_save_upload(), a foreach loop contains a switch statement that in turn has 'continue' after each case. My understanding is that 'continue' in this context means the same as 'break', and if that is what is meant then it should be written thus.

Note: In PHP the switch statement is considered a looping structure for the purposes of continue. continue behaves like break (when no arguments are passed). If a switch is inside a loop, continue 2 will continue with the next iteration of the outer loop.

http://php.net/manual/en/control-structures.continue.php

If 'continue' was actually meant to move on to the next 'foreach' item (which seems very likely in this case), then 'continue 2;' or perhaps a 'return' of some sort is needed and this is a bug: it would appear this loop is checking conditions on files in preparation for saving them, and simply breaking the switch means bad files are being manipulated.

An extract of the code starting line 742:

  foreach ($uploaded_files as $i => $file_info) {
    // Check for file upload errors and return FALSE for this file if a lower
    // level system error occurred. For a complete list of errors:
    // See http://php.net/manual/features.file-upload.errors.php.
    switch ($file_info->getError()) {
      case UPLOAD_ERR_INI_SIZE:
      case UPLOAD_ERR_FORM_SIZE:
        drupal_set_message(t('The file %file could not be saved because it exceeds %maxsize, the maximum allowed size for uploads.', array('%file' => $file_info->getFilename(), '%maxsize' => format_size(file_upload_max_size()))), 'error');
        $files[$i] = FALSE;
        continue;

      case UPLOAD_ERR_PARTIAL:
...[snip]...
CommentFileSizeAuthor
#10 2833099-10.patch1.36 KBjoshua.boltz

Comments

rivimey created an issue. See original summary.

rivimey’s picture

Issue summary: View changes
cilefen’s picture

Issue summary: View changes

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

steinmb’s picture

Issue tags: +PHP 7.3
alexpott’s picture

Status: Active » Closed (duplicate)
Related issues: +#2989734: PHP 7.3 compatibility

This will be fixed in #2989734: PHP 7.3 compatibility

joshua.boltz’s picture

StatusFileSize
new1.36 KB

Attached quick, simple patch that removes the warnings due to PHP 7.3 and the continue/switch statements.