Problem/Motivation

A page with a VBO field crashes with "Allowed memory size exhausted" when the view's exposed input contains an empty array anywhere, at any nesting level.

ViewsBulkOperationsBulkForm::getExposedInput() recurses into every array value:

foreach ($exposed_input as $name => $value) {
  if (\is_array($value)) {
    $exposed_input[$name] = $this->getExposedInput($value);
  }
}

When it recurses with an empty array, the check at the top of the method (if (\count($exposed_input) === 0)) treats it as "no input given" and loads the view's full exposed input again. That restarts the walk from the top, so the recursion never ends.

I hit this with a custom exposed date range filter that uses datetime form elements, whose empty value contains an empty array. Any filter or module that puts an empty array into exposed input triggers it.

Steps to reproduce

  1. Create a view with a VBO field and a page display.
  2. Make the exposed input contain an empty array, for example with:
    function mymodule_views_pre_view(\Drupal\views\ViewExecutable $view) {
      if ($view->id() === 'my_view') {
        $view->setExposedInput(['test' => []]);
      }
    }
  3. Visit the page. PHP runs out of memory in getExposedInput().

Proposed resolution

Only recurse into non-empty arrays:

if (\is_array($value) && \count($value) > 0) {

Empty arrays are kept as they are, so comparing old and current exposed input still works.

Remaining tasks

  • Create a merge request with the fix.
  • Add test coverage for exposed input with an empty array.
  • Review.

User interface changes

None.

API changes

None.

Data model changes

None.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

titacvetkovic created an issue. See original summary.

gurkawal made their first commit to this issue’s fork.

gurkawal’s picture

Hi @titacvetkovic

I was able to reproduce the issue and have prepared a fix.

The issue occurs when getExposedInput() receives an empty array. Since array values are processed recursively, an empty array can cause the method to reload the exposed input and enter repeated recursion.

The fix ensures that recursive processing is performed only for non-empty arrays:

if (\is_array($value) && \count($value) > 0) {
  $exposed_input[$name] = $this->getExposedInput($value);
}

I also added kernel test coverage to verify:

  • Top-level empty arrays are preserved correctly.
  • Nested empty arrays do not trigger recursion.
  • Non-empty

nested arrays continue to be processed and sorted as expected.

An MR has been created with the fix and corresponding test coverage.

gurkawal’s picture

Status: Active » Needs review

graber made their first commit to this issue’s fork.

  • graber committed 368823de on 4.4.x authored by gurkawal
    Issue #3625570: Prevent recursion on empty exposed input arrays
    
graber’s picture

Status: Needs review » Fixed

Looks good, thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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