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
- Create a view with a VBO field and a page display.
- 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' => []]); } } - 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.
Issue fork views_bulk_operations-3625570
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
Comment #4
gurkawal commentedHi @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:
I also added kernel test coverage to verify:
nested arrays continue to be processed and sorted as expected.
An MR has been created with the fix and corresponding test coverage.
Comment #5
gurkawal commentedComment #8
graber commentedLooks good, thanks!