Skip to content

Commit

Permalink
[BUGFIX] Reset belog search constraints on memory exhaustion
Browse files Browse the repository at this point in the history
If a backend user uses the search in belog with no boundaries or sets a
custom date limit with boundaries that are too wide, the script
execution will experience a "Allowed memory of ... exhausted ..."
fatal error in PHP.

Because the search constraints are saved in the backend users uC
nonetheless, any further effort to access the belog module would result
in a fatal error, thus making it unusable.

This patch makes the belog module detect, if the script execution fails
because of an exhausted memory and reset the search constraints to its
initial values.

Resolves: #89256
Releases: master, 9.5
Change-Id: I08f60399aed3a209cf98f5b33e311d22288e05ce
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61878
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Jörg Bösche <typo3@joergboesche.de>
Tested-by: Steffen Frese <steffenf14@gmail.com>
Tested-by: Sascha Rademacher <sascha.rademacher+typo3@gmail.com>
Tested-by: Tobi Kretschmann <tobi@tobishome.de>
Tested-by: Julian Geils <j_geils@web.de>
Tested-by: Felix <f.pachowsky@neusta.de>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Jörg Bösche <typo3@joergboesche.de>
Reviewed-by: Steffen Frese <steffenf14@gmail.com>
Reviewed-by: Sascha Rademacher <sascha.rademacher+typo3@gmail.com>
Reviewed-by: Tobi Kretschmann <tobi@tobishome.de>
Reviewed-by: Julian Geils <j_geils@web.de>
Reviewed-by: Felix <f.pachowsky@neusta.de>
  • Loading branch information
IndyIndyIndy authored and d3pendent committed Oct 8, 2019
1 parent 31dd958 commit 1960fac
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions typo3/sysext/belog/Classes/Controller/BackendLogController.php
Expand Up @@ -113,6 +113,7 @@ public function listAction(Constraint $constraint = null, int $pageId = null, st
$this->persistConstraintInBeUserData($constraint);
}
$constraint->setPageId($pageId);
$this->resetConstraintsOnMemoryExhaustionError();
$this->setStartAndEndTimeFromTimeSelector($constraint);
$this->forceWorkspaceSelectionIfInWorkspace($constraint);
$logEntries = $this->logEntryRepository->findByConstraint($constraint);
Expand Down Expand Up @@ -172,6 +173,24 @@ protected function persistConstraintInBeUserData(Constraint $constraint)
$GLOBALS['BE_USER']->pushModuleData(static::class, serialize($constraint));
}

/**
* In case the script execution fails, because the user requested too many results
* (memory exhaustion in php), reset the constraints in be user settings, so
* the belog can be accessed again in the next call.
*/
protected function resetConstraintsOnMemoryExhaustionError()
{
$reservedMemory = new \SplFixedArray(187500); // 3M
register_shutdown_function(function () use (&$reservedMemory) {
$reservedMemory = null; // free the reserved memory
$error = error_get_last();
if (strpos($error['message'], 'Allowed memory size of') !== false) {
$constraint = $this->objectManager->get(Constraint::class);
$this->persistConstraintInBeUserData($constraint);
}
});
}

/**
* Create a sorted array for day and page view from
* the query result of the sys log repository.
Expand Down

0 comments on commit 1960fac

Please sign in to comment.